2
为什么析构函数执行两次?
#include <iostream> using namespace std; class Car { public: ~Car() { cout << "Car is destructed." << endl; } }; class Taxi :public Car { public: ~Taxi() {cout << "Taxi is destructed." << endl; } }; void test(Car c) {} int main() { Taxi taxi; test(taxi); return 0; } 这是输出: …