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 the use of ::(scope resolution operator)?
what is pre-processor in C++?
Describe exception handling concept with an example?
What language does google use?
What are advantages of using friend classes?
What is the advantage of c++ over c?
What is a breakpoint?
Explain function overloading and operator overloading.
What is a base class?
What is expression parser in c++
Will this c++ program execute or not?
Which operator cannot be overloaded c++?
Explain the operation of overloading of an assignment operator.
Can recursive program be written in C++?
Can you please explain the difference between overloading and overriding?