Answer Posted / binoy mathew
#include <iostream>
#include <stdlib.h>
class t
{
public:
t()
{
printf("in constr");
}
private: // note that constructor is private here
~t()
{
printf("in destr");
}
};
int main()
{
t *t1 = new t; // create a new obj
delete t1; // delete the obj, which calls destructor
return 0;
}
Try to compile the above code.
following error results...
[root@localhost Desktop]# g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:13: error: ‘t::~t()’ is private
tt.cpp:: error: within this context
[root@localhost Desktop]#
....implies, we can't have destructor private.
Is This Answer Correct ? | 1 Yes | 3 No |
Post New Answer View All Answers
How do I run a program in notepad ++?
In inline " expression passed as argument are evalauated once " while in macro "in some cases expression passed as argument are evaluated more than once " --> i am not getting it plz help to make me understand....
What language is a dll written in?
What is DlgProc?
What is lambda in c++?
Explain the concept of copy constructor?
What is polymorphism in c++? Explain with an example?
Explain the static member function.
What does flush do?
Explain how we implement exception handling in c++?
What is ofstream c++?
What is std :: flush?
What is the best c++ book?
Can circle be called an ellipse?
What is the use of endl in c++?