I have an abstract class
namespace AComp
{
class A
{
public:
virtual void func() = 0;
virtual ~A();
};
A::~A() { }
}
I also have an abstract sub-class which does not provide implementation for the pure virtual member
namespace BComp
{
class B : public AComp::A
{
public:
virtual void func() override = 0;
virtual ~B() override;
};
B::~B() { }
}
Then I have a subclass providing implementation
namespace CComp
{
class C : public BComp::B
{
public:
virtual void func() override;
};
void C::func() { }
}
Finally, in my class which uses class C I have
AComp::A * instanceOfA = new CComp::C();
The linker throws the following error
undefined reference to 'vtable for B'
I thought it was something really stupid, but I cannot figure out what the issue is.
This code is to run on an ESP-32 microprocessor and it's all written using VisualCode and the ESP-IDF framework, where: A is in component Acomp, B is in component Bcomp, C is in component Ccomp and the calling code is in the main App
I've run the code through several online compilers and there appears to be no issues, however I do get the linker error
Compiler info
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- The ASM compiler identification is GNU
-- Found assembler: A:/espressif/.espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: A:/espressif/.espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: A:/espressif/.espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building ESP-IDF components for target esp32