CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Posts
    23

    Referring to previously-defined class in a namespace split acorss files

    I get a syntax error for referring to a previously defined class.


    file first.cpp
    ---------
    namespace NS {

    class C : public B {
    int m;
    }


    }


    file second.cpp
    ------------------
    namespace NS {

    B inst = new C(); // ------- Syntax Error: Doesn't recognize "C" from first.cpp.

    }


    I also used "using namespace NS" in second.cpp with no success.
    Does someone know how to resolve this? (I am using Visual C++).

    thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Referring to previously-defined class in a namespace split acorss files

    The definition of C should be in a header so that it could be included in second.cpp
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

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