C
Charles Jamieson
I declare a class
class myClass{
public:
~myClass();
class myClass{
public:
~myClass();
Charles said:obj.~myClass();
Had I placed this line in main(), when main() is exited the
destructor would not be called again.
Inside this function I destroy the object as follows
obj.~myClass();
Charles said:I declare a class
class myClass{
public:
~myClass();
.
.
.
}
In main() I have the line
myClass obj;
I then invoke a function with the prototype
void func( myClass& obj );
Inside this function I destroy the object as follows
obj.~myClass();
Had I placed this line in main(), when main() is exited the
destructor would not be called again.
Since I passed the object by reference, I expect that anything I do in
the function is the same had I done it in the calling routine. Yet in
this case, when main terminates, the destructor is invoked again.
I declare a class
class myClass{
public:
~myClass();
.
.
.
}
In main() I have the line
myClass obj;
I then invoke a function with the prototype
void func( myClass& obj );
Inside this function I destroy the object as follows
obj.~myClass();
Had I placed this line in main(), when main() is exited the
destructor would not be called again.
Since I passed the object by reference, I expect that anything I do in
the function is the same had I done it in the calling routine. Yet in
this case, when main terminates, the destructor is invoked again.
What is the reasoning behind this behavior?
-charles
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.