为什么以下代码在使用 gcc 4.7.2 和 MSVC-11.0 编译时会给出不同的输出?
#include <iostream>
class Base
{
public:
Base()
{
std::cout << "Base::Base() \n";
}
~Base()
{
std::cout << "Base::~Base() \n";
}
};
class Derived : public Base
{
public:
Derived()
{
std::cout << "Derived::Derived() \n";
}
~Derived()
{
std::cout << "Derived::~Derived() \n";
}
};
void foo(Base) {}
int main()
{
Derived instance;
foo(instance);
}
GCC 4.7.2
基数::基数()
派生::派生()
基数::~基数()
派生的::~派生的()
基数::~基数()
MSVC-11.0
基数::基数()
派生::派生()
基数::~基数()
基数::~基数()
为什么 MSVC-11.0 不打印第二个Derived::~Derived()
?