简体   繁体   English

纯虚拟类和对vtable的错误未定义引用

[英]Pure virtual classes and the error undefined reference to `vtable

I'm trying to implement a pure virtual class and derived class, but I am getting the following error. 我正在尝试实现纯虚拟类和派生类,但出现以下错误。

    /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /tmp/ccvROhIa.o: in function `main':
main.cpp:(.text+0x1ea): undefined reference to `vtable for bca2016_vol1_amdt1'
/usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /tmp/ccvROhIa.o: in function `bca2016_vol1_amdt1::~bca2016_vol1_amdt1()':
main.cpp:(.text._ZN18bca2016_vol1_amdt1D2Ev[_ZN18bca2016_vol1_amdt1D5Ev]+0xd): undefined reference to `vtable for bca2016_vol1_amdt1'
collect2: error: ld returned 1 exit status

I'm still new to c++, so I'm trying to learn what's wrong and why it's wrong. 我还是c ++的新手,所以我试图了解什么是错误的以及为什么它是错误的。 From my research it seems like it's primarily to do with the linker and the most common reason for this is that a virtual function hasn't been declared or that a virtual destructor hasn't been declared, though i'm pretty sure I have declared it? 从我的研究看来,这似乎主要与链接器有关,并且最常见的原因是未声明虚拟函数或未声明虚拟析构函数,尽管我敢肯定我已经声明了它?

In file bca2016_vol1_amdt1.cpp you use wrong class name bca (thus providing implementations for pure virtual functions of class bca , which is well formed). 在文件bca2016_vol1_amdt1.cpp使用错误的类名bca (因此提供实现的用于类的纯虚函数bca ,这是良好形成的)。 It should be bca2016_vol1_amdt1 . 应该是bca2016_vol1_amdt1

Also, bca2016_vol1_amdt1.cpp must include bca2016_vol1_amdt1.h . 另外, bca2016_vol1_amdt1.cpp必须包含bca2016_vol1_amdt1.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM