c++: problem with classes


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: c++: problem with classes

  1. #1
    Join Date
    Sep 2006
    Posts
    13

    Question c++: problem with classes

    hey you guys,

    the problem is that i have 2 classes (say A,B) ,
    class A have a pointer on class B
    <code>
    class A
    { B* b;};
    </code>
    and class B have a member variable for type class A
    <code>
    class B
    {A a;};
    </code>
    this is seems to be a problem and the compiler retrun an error say
    'a' uses undefined class 'A' although i am declaring the header of A
    <code>
    #include "A.h"
    class B
    {A a;};
    </code>

    anybody have any idea abt wat might be the problem here
    thnx 4 ur time and concern

  2. #2
    Join Date
    May 2006
    Posts
    176
    I think your A class should contain a short forward declaration of B:

    Code:
    // --- A.h file ---
    
    class B;
    
    class A
    {
        B * b;
    };
    
    
    // --- B.h file ---
    
    #include "A.h"
    
    class B
    {
        A a;
    };
    I hope this helps.
    Last edited by Viorel; 09-14-2006 at 09:58 AM.

Similar Threads

  1. classes and arrays problem
    By hiya in forum C++
    Replies: 3
    Last Post: 04-08-2005, 12:05 PM
  2. Java Applet Compiler problem?
    By mdl in forum Java
    Replies: 3
    Last Post: 03-07-2005, 03:34 AM
  3. Replies: 0
    Last Post: 12-13-2001, 01:06 PM
  4. Problem w/C# Classes
    By Tim Brooks in forum .NET
    Replies: 1
    Last Post: 11-15-2001, 01:48 PM
  5. Replies: 0
    Last Post: 06-23-2000, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center