classes

This is a discussion on classes within the C++ Programming forums, part of the General Programming Boards category; Here goes me again, I'm sorry to be asking so many questions, which aren't all that inteligent. This time what ...

  1. #1
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483

    classes

    Here goes me again, I'm sorry to be asking so many questions, which aren't all that inteligent.

    This time what i need to do is have 2 classes and an object of the other class
    something like this:

    Code:
    class A1
    {
    B2 b;
    };
    class B2
    {
    A1 a;
    };
    How would you go about this?
    My Website
    010000110010101100101011
    Add Color To Your Code!

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    What are you really trying to do?

    If you could compile the code you posted, what do you think happens when you create an object of A1? It will create an object of B2, which in turns creates an object of A1 separate from the previous one, which in turns creates an object of B2 separate from the previous one, which in turn ......

    One thing that you can do is this:
    Code:
    class B2;
    
    class A1
    {
        B2* b;
    };
    
    class B2
    {
        A1* a;
    };

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    So it basicly enters an infinte loop when you try to do something like that? Interesting

    Well thanks, works now.
    My Website
    010000110010101100101011
    Add Color To Your Code!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 11:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 08:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21