Linker error on pure virtual function call with gcc

前端 未结 3 1748
-上瘾入骨i
-上瘾入骨i 2021-01-05 22:14

A friend and I had a very interesting discussion about the construction of Objects that ended up with this piece of code:

#include 

class Pa         


        
3条回答
  •  没有蜡笔的小新
    2021-01-05 22:33

    The compiler knows that when you call doSomething from inside the constructor, that call must reference doSomething in this class, even if it is virtual. So it will optimize away the virtual dispatch and instead just do a normal function call. Since the function is not defined anywhere, this results in an error at link-time.

提交回复
热议问题