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
Tell me can a pure virtual function have an implementation?
How can I disable the "echo" feature?
Which operations are permitted on pointers?
How to declare a pointer to an array of integers?
What does it mean to declare a member function as virtual?
How do you save a c++ program?
Can you please explain the difference between using macro and inline functions?
What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
How the virtual functions maintain the call up?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
Explain the term memory alignment?
Is java made in c++?
What is the maximum combined length of command line arguments including the space between adjacent arguments?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
What is Destructor in C++?