#include <iostream>
using namespace std;
class a
{
public:
static int s;
a(){++s; cout<<s;}
~a(){--s;cout<<s;}
};
int a::s;
class b:public a
{
public:
b():a(){++s;cout<<s;}
~b(){--s;cout<<s;}
};
int main()
{
a *one = new b;
delete one;
cin.get();
}
... Since destructor ~A() isn't declared as virtual and type of pointer "one" is A, when we delete pointer "one", only destructor of class A executes, s = 1 and output 1. Destructor of class B will not execute..
2023 Nov 10, 1:54:28 PM
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать