Thread: Can a inner class have a member of outer class type?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    A defines a structure and B defines some presentation, read- and write functions to it. Therefore B uses some state (member) variables which shall not be member of A, so it needs to be an own class.

    I could of course just do

    Code:
    class A
    {
    
    };
    
    class B
    {
          A mA;    // VS complains that A is undefined
    }
    ...which would rather be the same, at least for my. Why not for the compiler?

    I would like to use the inner class because this way it's in the namespace defined by the outer class.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    This still doesn't explain why B needs an instance of A, rather than storing (or being passed) a reference/pointer to an A.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Quote Originally Posted by pheres View Post
    B uses some state (member) variables which shall not be member of A, so it needs to be an own class.
    That means B's members functions depend on each other, so B needs it's own member variables. But the can't be part of A because A is needed by legacy code as well and this code relies on the memory layout of A.

    I guess there is no solution to the original problem and I've to split A and B.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM