RE: When should we use the single inheritance v.s private members

From: Rakesh Khanduja (rakesh_khanduja_at_hotmail.com)
Date: 02/18/04


Date: Tue, 17 Feb 2004 23:11:07 -0800


 Hi,
In case of single inheritance u can call functions of base class
In main also(directly) but in case of private members u cannot do this.
I am sending u the code so u can understand the logic when use single inheritance or when use private members as containers.(This provides the Datahinding).
#include "iostream.h"
class A
{
public:
        A(){};
        ~A(){};
        void f()
        {
                cout<<"hello";
        }
};
class B:public A
{
public:
        void fb()
        {
        f();
        }
};
class C
{
private:
        A a;
public:
        void fc()
        {
        a.f();
        }
};

int main(int argc, char* argv[])
{
        C c;
        c.fc();
        B b;
        b.f(); //In case of single inheritance u can call functions of base class
        //in main also but in case of private members u cannot do this
        return 0;
}



Relevant Pages

  • When should we use the single inheritance v.s private members
    ... I have a question regarding about single inheritance vs. private members - when we should use ... class MyClassA { ... or member function: ...
    (microsoft.public.dotnet.languages.vc)
  • private field is never assigned ; force comiler to stop complaining?
    ... know if there is a more relevant group. ... I have a series of private members in my class, ... reflection in a base class. ... basis for supressing or eliminating the compiler warning. ...
    (microsoft.public.dotnet.general)
  • Re: Having problem getting private members using reflection.
    ... Private members from the concrete class or the base class? ... there's one last bit of detail where private base class members are inaccessible via reflection on the derived type. ... I did some digging and the MSDN documentation states that the caller must have ReflectionPermission in order to get the private members of a class. ... Could someone please clarify on what I need to do in order for my code to be able to parse private members of my Page using reflection? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: private instance variable of derived class not always returned by base class getter?
    ... combination of private instance variables than can be accessed through ... getters declared in the base class. ... Private members can only be seen inside the ... The getters and setters of the base-class can only ...
    (comp.lang.java.help)
  • Re: OO Design question
    ... Today your base class *only* has common data. ... Pure data-only objects are well-expressed using structs. ... instantiating your structs as private members of the base class, ... also happens to be far more flexible than using multiple levels of ...
    (microsoft.public.dotnet.languages.csharp)