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 do you mean by persistent and non persistent objects?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
What is stl containers in c++?
What methods can be overridden in java?
What are arrays c++?
What is meant by the term name mangling in c++?
What are the five basic elements of a c++ program?
What do you understand by a pure virtual member function?
Will the following program execute?
Explain this pointer?
Is java the same as c++?
what is C++ exceptional handling?
Why was c++ made?
What are c++ data types?
Difference between delete and free.