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
Is c++ a low level language?
What is istream and ostream in c++?
What is a map in c++?
Do you know the problem with overriding functions?
Implement stack operations with pointers with appropriate exception checks.
What are the general quetions are in DEna bank manager IT/System interviews?
What are the restrictions apply to constructors and destructors?
Define namespace in c++?
What are the advantages of using friend classes?
Explain queue. How it can be implemented?
What is stack unwinding?
Which is better c++ or java?
What is fflush c++?
What are the advantages of using const reference arguments in a function?
Why do we use templates?