- Переменная класса "XBox" определяется с именем "lol".
- Переменная структуры "ConsoleTest" определяется с именем ez, а параметр { lol
- lol передается в поле консоли ez.
- Вызывается функция printBrand() поля консоли ez.
Код: Выделить всё
$ g++ main.cpp -o ../out/debug -std=c++17Код: Выделить всё
/usr/bin/ld: /tmp/main-181a59.o: in function `main':
main.cpp:(.text+0x58): undefined reference to `VirtualConsole::printBrand()'
/usr/bin/ld: /tmp/main-181a59.o: in function `VirtualConsole::VirtualConsole(VirtualConsole const&)':
main.cpp:(.text._ZN14VirtualConsoleC2ERKS_[_ZN14VirtualConsoleC2ERKS_]+0x13): undefined reference to `vtable for VirtualConsole'
/usr/bin/ld: /tmp/main-181a59.o: in function `VirtualConsole::VirtualConsole()':
main.cpp:(.text._ZN14VirtualConsoleC2Ev[_ZN14VirtualConsoleC2Ev]+0xf): undefined reference to `vtable for VirtualConsole'
/usr/bin/ld: /tmp/main-181a59.o: in function `XBox::~XBox()':
main.cpp:(.text._ZN4XBoxD0Ev[_ZN4XBoxD0Ev]+0x23): undefined reference to `operator delete(void*, unsigned long)'
/usr/bin/ld: /tmp/main-181a59.o:(.data.rel.ro._ZTI4XBox[_ZTI4XBox]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/bin/ld: /tmp/main-181a59.o:(.data.rel.ro._ZTI4XBox[_ZTI4XBox]+0x10): undefined reference to `typeinfo for VirtualConsole'
/usr/bin/ld: /tmp/main-181a59.o:(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Код: Выделить всё
#include
// Fully aware im using the struct keyword, shouldn't be causing any issue though
struct VirtualConsole {
// public is just a stylization choice in the structs
public:
virtual ~VirtualConsole() = default;
virtual void printBrand();
};
struct XBox: VirtualConsole {
public:
void printBrand() override {
printf("Hi chat this is an xbox");
};
};
struct ConsoleTest {
public:
ConsoleTest(VirtualConsole input)
: console{ input } {}
VirtualConsole console;
};
int main() {
XBox lol{};
ConsoleTest ez{ lol };
ez.console.printBrand();
}
Я пробовал: добавлять «public» при создании XBox, использовать компилятор clang, запускать компиляцию внутри каталога src, искать проблему в Google, искать подобное в переполнении стека проблемы.
Как исправить код?
Подробнее здесь: https://stackoverflow.com/questions/798 ... -same-file
Мобильная версия