problem with visual C++ 9 compile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabil035
    New Member
    • Mar 2008
    • 34

    problem with visual C++ 9 compile

    Well the problem is so frustrating for a any C++ developer


    I want to import call using this syntax


    #include.....
    class Imported;

    class NEWclass
    {
    Imported* imp;
    }

    the compiler considers "class Imported " as a new definition for the class Imported.
    Can anyone show me a way to import the class without calling the header file.

    thx.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What you are showing is called a forward reference. It's like a prototype for a class. It tells the compiler that Imported is a class even though the compiler hasn't yet seen the class declaration. This is enough info for the compiler to allow an Imported* without generating an error.
    [code=cpp]
    class Imported; //forward reference

    int main()
    {
    Imported* ptr; //OK
    }
    [/code

    However, if you use this pointer with say ptr->GetData(), then you will need to include the class declaration so the compiler can verify that there is an Imported::GetDa ta().

    Comment

    • RRick
      Recognized Expert Contributor
      • Feb 2007
      • 463

      #3
      Since your compiler is complaining that this is a redefinition of Imported, it sounds like the Imported header file is already included. Has some other header file included this object?

      Have you tried removing the forward declaration of Imported and see what happens?

      Comment

      • nabil035
        New Member
        • Mar 2008
        • 34

        #4
        thx


        Yes,it was a problem of includes,

        Comment

        Working...