0

this is my easy code to learn vitual class,this code can be complied by clion 。

class BaseA{
public:
    BaseA(){};
    ~BaseA(){};
    int a;
    virtual  void fuc()=0;
};
class DrivedA:public BaseA{
public:
    DrivedA(){};
    ~DrivedA(){};
    int b;
    void fuc() override{
    b=2;
    };
};

int main() {
    DrivedA drivedA;
    drivedA.fuc();

    return 0;
}

this is makeLists:

cmake_minimum_required(VERSION 3.21)
project(learn_gcc_and_classvitrualtable)

set(CMAKE_CXX_STANDARD 20)

add_executable(learn_gcc_and_classvitrualtable main.cpp)

but when i use gcc alone to compile it,it does not work with these error。 Is there anything wrong in my code or i use gcc in a wrong way... Could you please help me?

[myk@MYK learn_gcc_and_classvitrualtable]$ gcc main.cpp 
/usr/bin/ld: /tmp/ccY9AVjz.o:(.data.rel.ro._ZTI7DrivedA[_ZTI7DrivedA]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/bin/ld: /tmp/ccY9AVjz.o:(.data.rel.ro._ZTI5BaseA[_ZTI5BaseA]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
mikkkkk
  • 1
  • 2

0 Answers0