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
Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);
Why are pointers not used in c++?
What new()is different from malloc()?
Which software is best for c++ programming?
How is new() different from malloc()?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What is c++ & why it is used?
what is c++
Does there exist any other function which can be used to convert an integer or a float to a string?
What are the differences between new and malloc?
Write a program which uses functions like strcmp(), strcpy()? etc
What is function declaration in c++ with example?
What is the latest c++ standard?
On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?
Is dev c++ free?