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
Can the creation of operator** is allowed to perform the to-the-power-of operations?
Why c++ is better than c language?
What is the full name of logo?
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
Can constructor be private in c++?
What is stream and its types in c++?
What are the uses of typedef in a program?
What is extern c++?
Why is c++ still used?
What operator is used to access a struct through a pointer a) >> b) -> c) *
Why do we use constructor?
How much do coding jobs pay?
What are c++ manipulators?
To what does “event-driven” refer?
Can there be at least some solution to determine the number of arguments passed to a variable argument list function?