-
January 23rd, 2006, 11:21 PM
#1
Link Errors When Preprocessor is Used
Hi,
I get this very weird error when I wrote a program using a preprocessor and without using it. These is a short portion of the code:
.....
.....
A->function();
In another .cpp file,I have:
namespace HH;
.....
....
#ifdef _XX_
void return ClassName::function()
{
..... code here....
}
#endif
.......
where _XX_ is defined in the preprocessor listing
Also, I have implemented the function prototype in a header file.
When I build the program, I get a LNK 2001 error: Unresolved external symbol on the A->function()....
When I try to check the declaration and definition of the function, the program can link directly to the respective location.
However, when I commented out the #ifdef & #endif,
My program can build correctly.
Can anyone explain why is this so?I'm using Visual C++ 6.0
Thanks a lot.
-
January 23rd, 2006, 11:47 PM
#2
Re: Link Errors When Preprocessor is Used
where _XX_ is defined in the preprocessor listing
No _XX_ is not defined if it was it would have compiled. You are doing something wrong.
-
January 28th, 2006, 01:37 PM
#3
Re: Link Errors When Preprocessor is Used
It looks like scope resolution problem.
Most likely you did not specify a namespace. Without explicit qualifier call to a class that resides in a namespace will fail.
Use "using" directive in a cpp file:
using namespace HH
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|