what is the problem with under?

lovec 2001-12-10 07:56:05
#include<iostream.h>

class First{
public:
First(){cout<<"First Constructor"<<endl;};
virtual ~First();
virtual void GetID(){ cout<<_GetID();};
private:
virtual int _GetID() const = 0 ;
};

class Sec: public First {
public:
Sec(int id=2): ID(id) {cout<<"Second Constructor"<<endl;};
~Sec();
private:
int ID;
int _GetID() const { return ID ; };
};

void f(First& fir)
{
fir.GetID();
}
int main()
{
Sec sec;
f(sec);
return 1;
}

the result of compiling is:
att1% g++ VPriv.C
/var/tmp/cca0013C1.o: In function `main':
/var/tmp/cca0013C1.o(.text+0x58): undefined reference to `Sec::Sec(int)'
/var/tmp/cca0013C1.o(.text+0x80): undefined reference to `Sec::~Sec(void)'

and the version of g++ is 2.7

这个例子是我看了 孟岩 的与大虾对话中的“Virtually Yours -- Template Method模式”,临时写出来的,可能领悟的不透,大虾多多执教,小菜鸟感激涕零!
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovec 2001-12-10
  • 打赏
  • 举报
回复
ha,犯这样低级错误,真是失败啊,多谢hz129(孤星古雨) ,好的把分都给你了!
hz129 2001-12-10
  • 打赏
  • 举报
回复
virtual ~First(); --> virtual ~First() {}

~Sec(); --> ~Sec() {}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧