简体   繁体   中英

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. 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). It should be bca2016_vol1_amdt1 .

Also, bca2016_vol1_amdt1.cpp must include bca2016_vol1_amdt1.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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