RE: When should we use the single inheritance v.s private members
From: Rakesh Khanduja (rakesh_khanduja_at_hotmail.com)
Date: 02/18/04
- Next message: sashan: "Re: Emacs/Vim style buffer/window switching"
- Previous message: Rakesh Khanduja: "RE: Creating a .NET wrapper around C library"
- In reply to: Jodie: "When should we use the single inheritance v.s private members"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: sashan: "Re: Emacs/Vim style buffer/window switching"
- Previous message: Rakesh Khanduja: "RE: Creating a .NET wrapper around C library"
- In reply to: Jodie: "When should we use the single inheritance v.s private members"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|