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