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 understand by zombie objects in c++?
Which is best c++ or java?
Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.
What are guid? Why does com need guids?
What is the basic of c++?
Explain the use of virtual destructor?
Explain selection sorting?
What is a string example?
What is class invariant in c++?
What is the return value of the insertion operator?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create
What is tellg () in c++?
What are inline functions? What is the syntax for defining an inline function?
What is a virtual destructor? Explain the use of it?
What is the difference between global int and static int declaration?