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