Undefined Symbols: "vtable" and "typeinfo"
In the provided code, a linking error arises with the following messages:
Undefined symbols: "vtable for Obstacle", referenced from: Obstacle::Obstacle()in Myworld.o "typeinfo for Obstacle", referenced from: typeinfo for RECTANGLEin RECTANGLE.o typeinfo for CIRCLEin CIRCLE.o
Understanding "vtable" and "typeinfo"
Resolving the Error
The root cause of this error is most likely that the abstract base class Obstacle contains non-pure virtual functions. When a class declares a pure virtual function (virtual void Method() = 0;), it signifies that the derived classes must override the implementation.
If you have defined non-pure virtual functions in Obstacle, the compiler expects to find their implementations either in the base class or in the derived classes. However, if these implementations are not provided, the compiler generates internal structures (vtable and typeinfo) that rely on those functions. When linking, the missing functions lead to the undefined symbol errors.
Solution
To resolve this issue, ensure that all virtual methods in the abstract base class Obstacle are declared as pure virtual functions. This forces the derived classes to override and implement these methods. By doing so, the correct virtual method implementations will be provided, and the linking process should succeed without the undefined symbol errors.
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3