CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    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.

  2. #2
    Join Date
    Nov 2005
    Location
    India, Kerala, Trivandrum
    Posts
    37

    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.

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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
  •  





Click Here to Expand Forum to Full Width

Featured