如题,查了c++primer,也没有详细解释。提示如下错误
g++ -O2 main.cpp -lm -o main
C:\Users\Traeyee\AppData\Local\Temp\ccgVqs5n.o:main.cpp:(.text.startup+0x13): undefined reference to `test2::show2()'
collect2.exe: error: ld returned 1 exit status
//A.h
#ifndef A_H
#define A_H
class test1
{
public:
void show();
};
#endif
//A.cpp
void test1::show()
{
cout << "TTT" << endl;
}
//B.h
#ifndef B_H
#define B_H
#include "A.h"
class test2 : public test1
{
public:
void show2();
};
#endif
//B.cpp
void test2::show2()
{
cout << "2222\n";
}
//main.cpp
#include <iostream>
#include "A.h"
#include "B.h"
using namespace std;
int main()
{
test2 TP;
TP.show2();
return 0;
}