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 c++ programmers do?
How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?
What is the extension of c++?
What is the difference between cin.read() and cin.getline()?
Which one is a preferred language C or C++? Why?
Can we run c program in turbo c++?
What is a static element?
Does c++ have foreach?
Is c# written in c++?
what are the events occur in intr activated on interrupt vector table
Write about the access privileges in c++ and also mention about its default access level?
What is the difference between strcpy() and strncpy()?
What is function prototyping? What are its advantages?
What are the uses of static class data?
What is the purpose of ios::basefield in the following statement?