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
Do you know what are pure virtual functions?
How many keywords are used in c++?
Can we use this pointer inside static member function?
What are keywords in c++?
What is namespace std; and what is consists of?
What is near, far and huge pointers? How many bytes are occupied by them?
What is a try block?
Can a program run without main?
Distinguish between new and malloc and delete and free().
Does a derived class inherit or doesn't inherit?
Why are pointers not used in c++?
What is the importance of mutable keyword?
What is a static element?
Is multimap sorted c++?
What is a node class in c++?