关于网友提出的“ __interface到底能不能用在非托管环境?”问题疑问,本网通过在网上对“ __interface到底能不能用在非托管环境?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: __interface到底能不能用在非托管环境?
描述: __interface非托管环境下能编译运行(__abstract就不行),但是我们知道通过基类指针析构子类对象时。。。
__interface I_MyInterface{
virtual void work() =0;
};
class Test: public I_MyInterface{
public:
virtual void work(){}
virtual ~Test(){ cout << "object of test is destroying..." << endl; }
};
int main(){
I_MyInterface* imi = new Test;
delete imi;
return 0;
}
子类Test析构函数根本没运行,可__interface又不允许定义析构函数,有解否?
解决方案1: 父类没有定义虚析构函数。
#include
using namespace std;
struct I_MyInterface{
virtual void work() =0;
virtual ~I_MyInterface(){}
};
class Test: public I_MyInterface{
public:
virtual void work(){}
virtual ~Test(){ cout << "object of test is destroying..." << endl; }
};
int main(){
I_MyInterface* imi = new Test;
delete imi;
return 0;
}
以上介绍了“ __interface到底能不能用在非托管环境?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3791057.html