Codeblocks undefined reference to vtable (non-QT)

Source: Internet
Author: User

A small Summary of undefined reference to vtable

1. Cause 1: The Destructor or constructor in the base class has no function implementation

2. cause 2: If your destructor has a function body but still reports this error, check whether it is an inline function definition. You can try to put the function implementation in. in the CPP file, do not place it in. h.

3. Cause 3: If none of the above are against .... Amount... I am so hard!

In the end, I am trying to solve the problem...

Situation description: There is a base class M, sub-classes A1 and A2 all inherit m... Now A1 and A2Code, Except for different class names.

M functions are implemented by function bodies and placed in the corresponding CPP file, so they do not meet the requirements of 1, 2...

A1.h has the following code:

A1 (bool ap = false): m (false), mlen (0 ){}

~ A1 (); destructor are implemented in the. cpp file.

A1 can be compiled, but after A2 is added, the same structure code will report a vtable error. Crashing.

Moving the implementation of A2 to. cpp does not report the vtable error, but reports the underference to A2 (bool) error.

That is, change:

. H

A2 (bool ap = false );

. Cpp

A2 (bool AP): mm (false), mlen (0)

{

}

 

The final proof is that a2.cpp and a2.h are not added to the project to select debug and release .... Right-click the. h/. cpp file and select properties...> build.

(⊙ _ ⊙) This type of vtable-related error is the first time I saw O (partition _ tables) O Haha ~ The solution is fine. However, I am too fond of myself .... Pay attention to it later!

 

Refer to the following URL

Http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html

 

Http://stackoverflow.com/questions/1095298/gcc-c-linker-errors-undefined-reference-to-vtable-for-xxx-undefined-refere

 

Http://bytes.com/topic/c/answers/157797-undefined-reference-vtable-base

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.