i am using vc++
[code=cpp]
#include<iostre am>
using namespace std;
class esteem;
class zen;
class maruti
{
char name[10];
public:
maruti(){}
void getdata()
{
cout<<"get name\n";
cin>>name;
}
maruti* getobject()
{
if (name == "esteem")
return esteem.Instance ();
else
return new zen();
}
virtual void print() {}
};
class esteem:public maruti
{
static esteem* pinstance; // initialize pointer
public:
esteem(){}
static esteem *Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new esteem(); // create sole instance
}
return pinstance; // address of sole instance
}
void print()
{
cout<<"in esteem\n";
}
};
class zen:public maruti
{
public:
zen(){}
void print()
{
cout<<"in zen\n";
}
};
int main()
{
maruti *m,*k,j;
m=&j;
m->getdata();
k = m->getobject();
k->print();
return 0;
}
[/code]
this is the whole code
i am getting errors
error C2512: 'zen' : no appropriate default constructor available
this is the main error
so tried another way to create the object of esteem class
but even this is showing erros
please help me
[code=cpp]
#include<iostre am>
using namespace std;
class esteem;
class zen;
class maruti
{
char name[10];
public:
maruti(){}
void getdata()
{
cout<<"get name\n";
cin>>name;
}
maruti* getobject()
{
if (name == "esteem")
return esteem.Instance ();
else
return new zen();
}
virtual void print() {}
};
class esteem:public maruti
{
static esteem* pinstance; // initialize pointer
public:
esteem(){}
static esteem *Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new esteem(); // create sole instance
}
return pinstance; // address of sole instance
}
void print()
{
cout<<"in esteem\n";
}
};
class zen:public maruti
{
public:
zen(){}
void print()
{
cout<<"in zen\n";
}
};
int main()
{
maruti *m,*k,j;
m=&j;
m->getdata();
k = m->getobject();
k->print();
return 0;
}
[/code]
this is the whole code
i am getting errors
error C2512: 'zen' : no appropriate default constructor available
this is the main error
so tried another way to create the object of esteem class
but even this is showing erros
please help me
Comment