新添加一個類,定義了構造函數和析構函數。其中析構函數只申明沒有定義。
鏈接時遇到如下的問題:
../local_gui/.libs/lib_local_gui.a(monthcalendar.o): In function `monthcalendar':
localgui/monthcalendar.cpp:208: undefined reference to `vtable for monthcalendar'
localgui/monthcalendar.cpp:208: undefined reference to `vtable for monthcalendar'
localgui/monthcalendar.cpp:208: undefined reference to `vtable for monthcalendar'
localgui/monthcalendar.cpp:208: undefined reference to `vtable for monthcalendar'
添加析構函數的定義,就一切正常了。
不過簡單測試下構造函數和其它成員函數只聲明不定義,好像沒有這個問題。
That is the most obscure error message the gcc produces, but the reason
is usually simple:
The compiler has to put the vtable into an object file. It puts it into
the object file where the definition of the first non-inline member
function is. If it is missing, you get this rather unhelpful linker
error. Please check the existence of the definitions of your member
functions.
Argh, you're right. I didn't provide an implementation for one of the
two methods in the subclass, but I declared it in the subclass. I just
removed the declaration so that the default implementation of the base
class will be used, which is what I want at this point.
http://bytes.com/topic/c/answers/161894-undefined-reference-vtable