How to access the base constructor???
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sample
{
sample()//sample constructor declared in private part
{
a=10;
}
int a;
static sample*pp;
public:
static sample* create()
{
pp=new sample;//creating sample class object
return pp;
}
void show()
{
cout<<a;
}
};
class derived:public sample
{
int x;
public:
derived() //derived constructor declared in public part
{ //how to access the base class' "sample" constructor
x=20; //here...the error is present here..cannot access
} // base class constructor
};
sample* sample::pp;
void main()
{
derived obj1;//creating derived object
getch();
}
/* my question is ..this program will not compile because we cannot access the base class' (here is sample) constructor because it is declared in private part in base..then HOW CAN WE CRATE AN OBJECT OF DERIVED CLASS..i tried a lot but cannot find the solution..actually this is possible or not..do not try this program to run in turbo or vc++ compiler.because you cannot create private constructor in these..but private constructor is possible in unix,linux c,c++*/
|