error C2079: 'CLASSA::objectb' uses undefined class 'CLASSB'

This is a discussion on error C2079: 'CLASSA::objectb' uses undefined class 'CLASSB' within the C++ Programming forums, part of the General Programming Boards category; confuse about how that works, here, i would try to make it very clear, Code: // file 2 CLASS B ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    142

    error C2079: 'CLASSA::objectb' uses undefined class 'CLASSB'

    confuse about how that works, here, i would try to make it very clear,

    Code:
    // file 2
    CLASS B
    {
    ...
    };
    
    // file 1
    
    CLASSB b; // forward declaration
    
    CLASS A
    {
    ...
    B b; // error 
    };
    
    but...,
    // file 1
    CLASS A
    {
    ...
    B * b; // okey
    };
    
    so what i did is,
    
    // file 1
    CLASS B
    {
    ...
    };
    
    CLASS A
    {
    ...
    B b; // now okey
    };
    why?? what was wrong there? what does the compiler mean by that? and why does the poitner version works?

    many thanks!
    Last edited by mickey; 06-28-2002 at 03:38 AM.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    As you've discovered, the compiler needs to see the full definition of a class before an instance of it can be constructed (it needs to know how big the object will be). The pointer version works because it's just a pointer not an actual instance.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    ahh., so how will i remedy the problem?

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    151
    Something like -

    //file 1

    #include "file2"

    CLASS A
    {
    ...
    B b;
    };

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    hiya, still same error,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  5. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21