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
What do you know about near, far and huge pointer?
what does the following statement mean? int (*a)[4]
List the advantages of inheritance.
What are the types of container classes?
What is the meaning of c++?
What is function overloading c++?
How do you flush a buffer in c++?
Which format specifier is used for printing a pointer value?
Can a program run without main in c++?
How can you quickly find the number of elements stored in a dynamic array?
What is the use of ::(scope resolution operator)?
Is java the same as c++?
Explain how overloading takes place in c++?
What is const pointer and const reference?
What is protected inheritance?