Ответ: нет.
Проверяем ответ:
#include <iostream>
class CBase
{
public:
~CBase()
{
std::cout << "~CBase" << std::endl;
}
};
class CDerive: public CBase
{
int *ptr;
public:
CDerive()
{
ptr = new int;
}
virtual ~CDerive()
{
std::cout << "~CDerive" << std::endl;
delete ptr;
}
};
int main()
{
{
CBase base;
}
std::cout << "Now CBase object must have been deleted " << std::endl;
{
CDerive derive;
derive.~CBase(); //main.cpp(40): error C2300: 'CDerive' : class does not have a destructor called '~CBase'
}
std::cout << "Now CDerive object must have been deleted " << std::endl;
std::cin.get();
return 0;
}
Проверяем ответ:
#include <iostream>
class CBase
{
public:
~CBase()
{
std::cout << "~CBase" << std::endl;
}
};
class CDerive: public CBase
{
int *ptr;
public:
CDerive()
{
ptr = new int;
}
virtual ~CDerive()
{
std::cout << "~CDerive" << std::endl;
delete ptr;
}
};
int main()
{
{
CBase base;
}
std::cout << "Now CBase object must have been deleted " << std::endl;
{
CDerive derive;
derive.~CBase(); //main.cpp(40): error C2300: 'CDerive' : class does not have a destructor called '~CBase'
}
std::cout << "Now CDerive object must have been deleted " << std::endl;
std::cin.get();
return 0;
}
Комментариев нет:
Отправить комментарий