DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006

    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
    class A
    { B* b;};
    and class B have a member variable for type class A
    class B
    {A a;};
    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
    #include "A.h"
    class B
    {A a;};

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

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

    // --- 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 08:58 AM.

Similar Threads

  1. classes and arrays problem
    By hiya in forum C++
    Replies: 3
    Last Post: 04-08-2005, 11:05 AM
  2. Java Applet Compiler problem?
    By mdl in forum Java
    Replies: 3
    Last Post: 03-07-2005, 02:34 AM
  3. Replies: 0
    Last Post: 12-13-2001, 12:06 PM
  4. Problem w/C# Classes
    By Tim Brooks in forum .NET
    Replies: 1
    Last Post: 11-15-2001, 12:48 PM
  5. Replies: 0
    Last Post: 06-23-2000, 02: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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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