undefined reference to xxxxx like mytype::constructor

The common error message in the GCC complaint compiler, will point to the common issue during the compile...

 

 

so if you get this type of issue , there an very easy way to handle on this.

 

 

I check in the think in  C++, about chapter 15,polymorphism &virtual functions, in section virtual function &constructor

 

I got an interesting guide line:

 

As a guideline, any time you have a virtual function in a class, you
should immediately add a virtual destructor (even if it does
nothing). This way, you ensure against any surprises later.

'

compair with the GCC guideline

http://gcc.gnu.org/faq.html#vtables

When building C++, the linker says my constructors, destructors or virtual tables are undefined, but I defined them

The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8. Based on this assumption, GCC will only emit the implicitly defined constructors, the assignment operator, the destructor and the virtual table of a class in the translation unit that defines its first such non-inline method.

Therefore, if you fail to define this particular method, the linker may complain about the lack of definitions for apparently unrelated symbols. Unfortunately, in order to improve this error message, it might be necessary to change the linker, and this can't always be done.

The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7.

 

 

solution is:

 

add the destruction to your class ,you can easy to find which function have been set as virtual not by your part of code, but the message or event macro.

 

why the GCC report as the undefined issue, because before to use the constructor, the compiler will check the vtable, if the object linked vtable's function not defined in your class, the complication of you class will faied by undefied reference to xxxxx...

 

this type issue can be easy found in a popular framework like wxwidget,MFC....

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值