2011年6月4日 星期六

有宣告解構式但未定義

如果你有宣告解構是但未定義的話

正常情況下,編譯器應顯示:
c++ -Wall -c main.cpp
c++ -Wall -c Base.cpp
c++ -Wall -c Derived.cpp
g++ -Wall main.o Base.o Derived.o -o a.out
main.o(.text+0x93): In function `main':
: undefined reference to `Derived::~Derived()'
Derived.o(.text+0x39): In function `Derived::Derived(std::string const&)':
: undefined reference to `vtable for Derived'
Derived.o(.text+0x69): In function `Derived::Derived(std::string const&)':
: undefined reference to `vtable for Derived'
*** Error code 1

但我遇到的狀況是:
c++  -c Student.cpp
c++  -c StudentOfEnglish.cpp
g++  main.o Student.o StudentOfEnglish.o -o a.out
StudentOfEnglish.o(.text+0x57): In function `StudentOfEnglish::StudentOfEnglish(std::string const&, std::string const&, std::string const&, std::vector<double, std::allocator<double> > const&)':
: undefined reference to `vtable for StudentOfEnglish'
StudentOfEnglish.o(.text+0xb7): In function `StudentOfEnglish::StudentOfEnglish(std::string const&, std::string const&, std::string const&, std::vector<double, std::allocator<double> > const&)':
: undefined reference to `vtable for StudentOfEnglish'
*** Error code 1


害我一直找建構式哪裡錯。

沒有留言:

張貼留言