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 are the main features of c++?
What is the difference between #define debug 0 and #undef debug?
what is C++ objects?
What are the various compound assignment operators in c++?
State the difference between pre and post increment/decrement operations.
What are the two types of comments, and how do they differ?
Is c++ a low level language?
What c++ is used for?
What causes a runtime error c++?
What are the types of pointer?
Search for: what is pair in c++?
What can I use instead of namespace std?
Why do we need function?
Is c++ double?
How did c++ get its name?