Answer Posted / sampurna pandey
yes, we can have both private constructor and destructor
and can use them with help of static function for example
class Base
{
static int i;
Base(){}
~Base(){}
public:
static Base *Creat_Object();
static void Destroy_Object(Base *p);
void Add()
{
cout<<i<<" Add function"<<endl;
}
};
int Base::i=0;
Base* Base::Creat_Object()
{
Base * ptr = new Base();
i=5;
return ptr;
}
void Base::Destroy_Object(Base *p)
{
delete p;
}
void main()
{
Base *temp = Base::Creat_Object();
temp->Add();
Base::Destroy_Object(temp);
}
correct me if i am wrong.
Is This Answer Correct ? | 21 Yes | 3 No |
Post New Answer View All Answers
What is flag in computer?
Will this c++ program execute or not?
Is c or c++ more useful?
What is encapsulation in c++ with example?
What is ctime c++?
How would you find out if a linked-list is a cycle or not?
Is c++ used anymore?
How compile and run c++ program in turbo c++?
Which operations are permitted on pointers?
Explain the term memory alignment?
Which software is best for programming?
Can comments be nested?
Why c++ is the best language?
What is microsoft c++ redistributable?
What are the rules for naming an identifier?