faqts

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

how can we access private data member or member function of one class to another ?

May 13th, 2008 08:05
i can do it, praveen tripathi, praveen tripathi


we can simply access data member or member function from one class to 
another:
we can make friend to both classes.
suppose i have to access private member of class 'a'in class 'b'
we will define friend class 'a' inside class 'b'.
for example:-
class a
{
    friend class b;
private:
    int v1;
};
class b
{
public:
    void inita()
    {
        a some_a;
        // Here we access the private member variable v1 
        // in A as if it were public
        some_a.v1 = 10;
    }
};
http://www.stupidarticles.com
http://www.halazona.com
http://www.shikapika.com
http://www.stakoza.com
http://www.uploadarticles.com
http://www.ganazat.com
http://www.damima.com
http://www.tarabiza.com
http://www.articlesxarticles.com
http://www.articlesfreedirectory.com