undefined reference to xxxxx like mytype::constructor
来源:互联网 发布:淘宝店铺粉丝机器 编辑:程序博客网 时间:2024/06/07 19:59
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 classthat are not pure-virtual must be defined, but does not require anydiagnostic for violations of this rule [class.virtual]/8. Based onthis assumption, GCC will only emit the implicitly definedconstructors, the assignment operator, the destructor and the virtualtable of a class in the translation unit that defines its first suchnon-inline method.
Therefore, if you fail to define this particular method, the linkermay complain about the lack of definitions for apparently unrelatedsymbols. Unfortunately, in order to improve this error message, itmight be necessary to change the linker, and this can't always bedone.
The solution is to ensure that all virtual methods that are notpure are defined. Note that a destructor must be defined even if itis 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....
- undefined reference to xxxxx like mytype::constructor
- [g++] undefined reference to (a constructor)
- Qt出现错误“undefined reference to `vtable for XXXXX.XXX”
- Qt出现错误 “undefined reference to `vtable for XXXXX.XXX”
- Qt出现错误“undefined reference to `vtable for XXXXX.XXX”
- gcc undefined reference to 'xxxxx'(部分转载)
- Qt出现错误"undefined reference to 'vtable for XXXXX.XXX'"
- undefined reference to symbol xxxxx和undefined symbol:xxxx错误的原因分析以及解决方法
- undefined reference to 'floor'/undefined reference to `&
- undefined reference to 'floor'/undefined reference to
- undefined undefined reference to `nfq_open'
- XXXXX() is undefined. Must explicitly invoke another constructor如何解决
- undefined reference to 'pthread_create'
- undefined reference to `_Unwind_Resume'
- undefined reference to `__ctype_b'
- undefined reference to rpl_malloc
- undefined reference to '__ctype_b'
- undefined reference to `__assert_fail'
- 水晶报表基础操作
- 公司旅游--金华武义二日游
- javascript误用html保留关键字作为方法名
- 为什么制作精良的权限系统卖5000元都很难,做个B2C网上商城卖10万都相对轻松一些?付出的代价与经济效益不成比例
- 怎样才能成为成为一个测试达人
- undefined reference to xxxxx like mytype::constructor
- samrty安装
- 今天你整理命名空间了吗? namespace using 优化了吗?【更适合菜鸟阅读】
- 小小树微博制作记录笔记(三)
- Baidu I fule you
- 一直谈失败的经历、再谈谈成功的经历、做软件真的不赚钱吗?4周搞定一个定制B2C网上购物、后台订单管理系统
- 【STM32 .Net MF开发板学习-20】蓝牙遥控智能小车(手机模式)
- Silverlight入门1 - Visual Studio 2010
- 当前我国的市场经济体制已经逐步建立起来并且正在迅速发展