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 binary search in c++?
What is the use of this pointer in c++?
What is a stack c++?
Is java a c++?
What are the two types of polymorphism?
Why is c++ considered difficult?
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
What do you mean by storage classes?
What is searching? Explain linear and binary search.
How to get the current position of the file pointer?
Which c++ operator cannot overload?
Can we use this pointer inside static member function?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What is a vector c++?
How is data hiding achieved in c++?