- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have two classes:
struct
Class1{
Class1()
{
LogAlert("call Class1()");
}
Class1(
const Class1 & _c)
{
LogAlert("call Class1(const Class1 & _c)");
}
~Class1()
{
LogAlert("call ~Class1()");
}
};
struct
Class2{
Class2()
{
LogAlert("call Class2()");
}
Class2(
const Class1 _c // without &) : prm(_c)
{
LogAlert("call Class2(const Class1 & _c)");
}
~Class2()
{
LogAlert("call ~Class2()");
}
Class1 prm;
};
Class1 tmp;
Class2 cls(tmp);
In result i have:
call Class1()
call Class1(const Class1 & _c)
call Class1(const Class1 & _c)
call Class2(const Class1 & _c)
call ~Class2()
call ~Class1()
call ~Class1()
Where one call of destructor?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I put your two instantiations into a main() and changed your LogAlerts to printfs to make this work. I tried with old and new versions of 8.1 and I don't see any problem. My output from any compiler shows all four dtor calls:
call Class1()
call Class1(const Class1 & _c)
call Class1(const Class1 & _c)
call Class2(const Class1 & _c)
call ~Class1()
call ~Class2()
call ~Class1()
call ~Class1()
What does "icc -V" tell you about your version? Do you have a standalone test case that works and demonstrates this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This problem show if"Enable C++ Exceptions (/EHsc)" is disable. But microsoft compiler work correct with this code.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page