所以我正在为班级做一个调试作业。我们不允许进行任何严重的代码更改。我的代码是:
#include <string>
#include <iostream>
#include <sstream>
class base_rec
{public:
base_rec (std::string contentstr):str(contentstr){};
void showme();
std::string str;};
class u_rec:public base_rec
{public:
u_rec():base_rec("undergraduate records"){};
void showme()
{std::cout<<"showme() function of u_rec class\t" <<str<<std::endl;};};
class g_rec:public base_rec
{public:
g_rec():base_rec("graduate records"){};
void showme()
{std::cout << "showme() function of a g_rec class\t"<<str<<std::endl;};};
int main()
{ base_rec *brp[2];
brp[1] = new u_rec;
brp[2] = new g_rec;
for (int i=0;i<1;i++)
{brp[i]->showme ();}
return 0;
}
但是,每当我尝试编译它时,都会收到错误消息:
/tmp/ccFm7Xvz.o:在函数
main': quiz2.cpp:(.text+0x54): undefined reference to
base_rec::showme()' collect2:错误:ld 返回 1 退出状态
我不完全确定这里有什么问题。有什么建议么?