c – 是现代g编译器解决的vtable错误的未定义引用?
发布时间:2020-12-16 09:56:37 所属栏目:百科 来源:网络整理
导读:根据 this虚函数必须定义,否则链接器抱怨报告错误“未定义引用vtable”,但为什么 ideone编译器没有为以下代码提供任何错误? #include iostreamusing namespace std;class Test{ public: Test() { cout"test() is calledn"; } virtual void test();};int ma
根据
this虚函数必须定义,否则链接器抱怨&报告错误“未定义引用vtable”,但为什么
ideone编译器没有为以下代码提供任何错误?
#include <iostream> using namespace std; class Test { public: Test() { cout<<"test() is calledn"; } virtual void test(); }; int main() { Test t; // your code goes here return 0; } 解决方法
您没有正确阅读文档.相关段落的第一句话说:
因此,预计您可能不会收到错误,尤其是因为您实际上并未调用test()(尽管构造函数的输出中存在谎言). 实际上,只有在下列情况下,您才有可能获得此诊断: >你调用一个你没有定义的虚函数 但不要搞错:你的程序有不确定的行为. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |