Warum linkt das nicht? PIMPL, undefined reference to vtable
-
Hoi!
Minimales Beispiel:#include <memory> struct A { struct Impl; static void deleteImpl(Impl* i); std::unique_ptr<Impl, decltype(&deleteImpl)> pimpl; A(); }; struct A::Impl { Impl() { } virtual ~Impl() { } virtual void foo(); }; struct B : A::Impl { B() { } virtual void foo() override { } }; void A::deleteImpl(Impl* i) { delete i; } A::A() : pimpl(new B, &deleteImpl) { } int main() { A a; }
Fehlermeldungen - Zeilenangaben stimmen nicht ganz da ich nur einen Teil kopiert habe!
/home/ethon/Code/Projekte/Nano/Nano/build> make -j2 [ 75%] Built target nano Scanning dependencies of target test [100%] Building CXX object CMakeFiles/test.dir/main.cpp.o Linking CXX executable test CMakeFiles/test.dir/main.cpp.o: In function `A::Impl::Impl()': /home/ethon/Code/Projekte/Nano/Nano/main.cpp:18: undefined reference to `vtable for A::Impl' CMakeFiles/test.dir/main.cpp.o: In function `A::Impl::~Impl()': /home/ethon/Code/Projekte/Nano/Nano/main.cpp:21: undefined reference to `vtable for A::Impl' CMakeFiles/test.dir/main.cpp.o:(.rodata._ZTI1B[_ZTI1B]+0x10): undefined reference to `typeinfo for A::Impl' collect2: error: ld returned 1 exit status make[2]: *** [test] Error 1 make[1]: *** [CMakeFiles/test.dir/all] Error 2 make: *** [all] Error 2 *** Fehler: Beendigungscode 2 ***
Vielen Dank & Grüße,
Ethon
-
In Zeile 20, meinten Sie:
virtual void foo() = 0;
?
-
Ahhh scheiße.
Hat man davon wenn man nur noch D programmiert hat.
Vielen Dank.