(.text._ZN7StudentC2Ev[_ZN7StudentC5Ev]+0x8): undefined reference to `vtable for Student'
/tmp/cc6ceKYh.o:(.rodata._ZTI3God[typeinfo for God]+0x8): undefined reference to `typeinfo for Student'
/tmp/cc6ceKYh.o:(.rodata._ZTI7Cheater[typeinfo for Cheater]+0x8): undefined reference to `typeinfo for Student'
/tmp/cc6ceKYh.o:(.rodata._ZTI3God[typeinfo for God]+0x8): undefined reference to `typeinfo for Student'
/tmp/cc6ceKYh.o:(.rodata._ZTI7Cheater[typeinfo for Cheater]+0x8): undefined reference to `typeinfo for Student'
collect2: ld returned 1 exit status
错误原因: 基类的虚函数只声明没有定义。
修改:1,用纯虚函数
2、写出虚函数的定义
本文探讨了在C++编程中遇到的基类虚函数只声明而未定义导致的链接错误,并提供了两种解决方案:一是使用纯虚函数声明,二是确保所有虚函数都有具体的实现。
3万+

被折叠的 条评论
为什么被折叠?



