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模式”,临时写出来的,可能领悟的不透,大虾多多执教,小菜鸟感激涕零!