CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: nested classes

  1. #1
    Join Date
    Jan 2001
    Posts
    39

    nested classes

    Hi,
    I have this problem:


    class A
    {
    class B
    {
    A a;
    };
    };




    The problem is that I can't use class A within class B because class A has not yet been declared entirely.
    Is there any way to declare a nest class outside the base class so the nested class can use the base class?
    Thanx.


  2. #2
    Join Date
    Sep 2000
    Location
    Munich (Germany)
    Posts
    764

    Re: nested classes

    Hi,

    I dont think that u can declare like that. Why do you want to declare an object of class A in class B? You can any way access all the members of A. Can you tell me a practical situation like that?

    John

    Let me know if got helped. If you got helped pls rate!!!

    Jus hav a look at http://www.bobbyzone.homestead.com
    Do you develop for PocketPCs? Try this tool for CeDatabases

    CeDatabase Manager 2.0

  3. #3
    Join Date
    Jan 2001
    Posts
    39

    Re: nested classes

    Hi,

    Yes you can declare this, its used mostly for hiding helper classes that can only been used by your base class and you don't want to accidentally use them.


  4. #4
    Join Date
    May 2001
    Posts
    5

    Re: nested classes

    Hi,

    Have you tried template, instead of writing class A in class B? And then when you call the class a, you can fill in the exact class insteadof the template.

    class A
    {
    class B
    {
    template a;
    };
    };

    Best regards,
    Hao


  5. #5
    Join Date
    Jan 2001
    Posts
    39

    Re: nested classes

    Hi,

    I'm not aware of this syntax of template keyword, can you spare a little time for explain it to me? I'll be grateful.
    Thanks for replying.



  6. #6
    Join Date
    May 2001
    Posts
    5

    Re: nested classes

    Hi,

    Sorry for my delay.

    According to your question, I think maybe we can find another way. For example,

    class A;
    class B{
    A a;
    };
    class A{
    B b;
    };

    Do you think it easier and can also satisfy you?

    Hao


  7. #7
    Join Date
    Jan 2001
    Posts
    39

    Re: nested classes

    No, sorry.
    I think that the solution will be something like this (I can't test it right now because I don't have a compiler in this computer)

    class A
    {
    class B;
    };

    class A::B
    {
    A a;
    };






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured