Thread: Local classes problem. Please help me

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    Local classes problem. Please help me

    Hello,
    i am posting the code with local classes. Please tell me how to access methods of local classes via the main class??

    Code:
    #include <iostream.h>
    #define N 10
    
    class A
    {
    	class B
    	{
    		int data;
    		public:
    			void setdata(int d);
    			void putdata();
    	}b;
    	public:
    		void setdata();
    		void putdata();
    };
    void A::putdata()
    {
    	B::putdata(); //how to access local class member function?
    }
    }
    void A::setdata()
    {
    	B::setdata(10); //how to access local class member function?
    }
    void A::B::putdata()
    {
    	cout<<data;
    }
    void A::B::setdata(int d)
    {
    	data=d;
    }
    
    int main(void)
    {
    return 0;
    }
    how shall i access the local classes member functions?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Just like you would access the non-static method of any other class - through an instance that you have (b).
    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).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple problem with classes
    By desdelaspalmas in forum C++ Programming
    Replies: 3
    Last Post: 12-01-2008, 03:15 AM
  2. Problem with classes
    By _DrMario_ in forum C++ Programming
    Replies: 4
    Last Post: 10-10-2006, 09:51 AM
  3. Problem with vectors and classes
    By applenerd in forum C++ Programming
    Replies: 6
    Last Post: 04-08-2006, 06:36 PM
  4. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM
  5. problem w/ nested templatized classes
    By *ClownPimp* in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2002, 07:58 AM