Thread: Innerclass problem

  1. #1

    Innerclass problem

    I came across this problem:
    I have two classes (classA & classB). classA has an inner class: classC

    Normally, to create a member of type inner class classC in classB I would do this:
    ClassA::ClassC member_;

    The definitions are in header files.
    Now I need classB in classA so I include classB. h in classA.h
    A variable of type classC needs to be passed with the constructor of classB.
    I can't include classA.h in class be because I already included ClassB. in classA.h

    The normal way (I think) to solve this problem (if I needed class A in classB.h is to say that classB is a class like this:
    class classB
      class classA;
      classA my_classA_;
    But now I need classC in classB
    class classA::classC;
    doesn't work.

    I solved the problem by taking classC out of classA but techicaly classC is part of classB so I'd rather put it in there.

    Any ideas?

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Uh... a little confusing (too much alphabet soup with those class names floating in my head). If you can give more of an idea to the application of this, it'd be easier to come up with a solution.

    Off the top of my head, though, I'd ask whether classA actually needs to include classB.h? Can any of the members of classA of type classB be made references or pointers? Without the actual code/problem, it is hard to tell if this is a viable solution, but replacing the include with a forward declaration would solve the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM