Thread: help with classes and pointers

  1. #1
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195

    help with classes and pointers

    I am trying to create an object "C" than contains an array of "B" objects, and each of these "B" objects conatins an array of "A" objects. Actually creating the objects is not the problem, the problem is that i can't figure out how to access the member functions of the A class, from a C class member function where the B class objects were created. It looks kinda like this:

    Code:
    class A {
      public:
        void memberFunctionA();
      private:
        int a_data;
    };
    
    class B {
      public:
         void memberFunctionB();
      private:
        A *a_ptr;
    };
    
    class C {
      public:
        void memberFunctionC();
      private:
        B *b_ptr;
    };
    
    ...
    ...
    ...
    
    B::B() {
      a_ptr = new A[4];
    } 
    
    void C::memberFunctionC() {
    
      b_ptr = new B[4];
    
    }
    
    ....
    ....
    ....
    
    int main()
    {
        C c;
         c.memberFunctionC();
    }

    What I want os to be able to use memberFunctionA() in memberFunctionC(). is there any way I can do this?
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  2. #2
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    Thats what I was looking for. My textbook doesn't have an example of friend classes. Thanks....

    I wonder if I could accomplish the same thing with handles, and if so which way is better, handles or friends?
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Q: Pointers to Classes '->' notation
    By Howie17 in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2008, 10:09 AM
  2. two-dimensional dynamic array of pointers to classes
    By Timo002 in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 06:18 AM
  3. Pointers to Classes || pointers to structures
    By C++Child in forum C++ Programming
    Replies: 24
    Last Post: 07-30-2004, 06:14 PM
  4. Help With pointers in classes.
    By indigo0086 in forum C++ Programming
    Replies: 12
    Last Post: 10-10-2002, 02:03 PM
  5. Pointers to classes
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2002, 09:25 PM