C++中的绝对难题!!!哪位高手可以解决这个问题呢?
#include<iostream>#include<string>usingnamespacestd;classFish{public:virtualFish*Clon...
#include<iostream>
#include<string>
using namespace std;
class Fish
{
public:
virtual Fish* Clone()=0;
virtual void Swim();
};
class Tuna:public Fish
{
public:
Fish* Clone()
{
return new Tuna(*this);
}
void Swim()
{
cout<<"Tuna swims fast in the sea"<<endl;
}
};
class Carp:public Fish
{
Fish* Clone()
{
return new Carp(*this);
}
void Swim()
{
cout<<"Carp swims slow in the lake"<<endl;
}
};
int main()
{
const int ARRAY_AIZE=4;
Fish* myFishes[ARRAY_AIZE]={NULL};
myFishes[0]=new Tuna();
myFishes[1]=new Carp();
myFishes[2]=new Tuna();
myFishes[3]=new Carp();
Fish* myNewFishes[ARRAY_AIZE];
for(int Index=0;Index<ARRAY_AIZE;++Index)
myNewFishes[Index]=myFishes[Index]->Clone();
for(int Inde=0;Inde<ARRAY_AIZE;++Inde)
myNewFishes[Inde]->Swim();
for(int Ind=0;Ind<ARRAY_AIZE;++Ind)
{
delete myFishes[Ind];
delete myNewFishes[Ind];
}
return 0;
}
以上这个函数是可以通过编译的。但是一点击运行就报错了!unresolved external symbol "public: virtual void __thiscall Fish::Swim(void)" (?Swim@Fish@@UAEXXZ
fatal error LNK1120: 1 unresolved externals
求C++专家级的人士来解答!
感激不敬啊! 展开
#include<string>
using namespace std;
class Fish
{
public:
virtual Fish* Clone()=0;
virtual void Swim();
};
class Tuna:public Fish
{
public:
Fish* Clone()
{
return new Tuna(*this);
}
void Swim()
{
cout<<"Tuna swims fast in the sea"<<endl;
}
};
class Carp:public Fish
{
Fish* Clone()
{
return new Carp(*this);
}
void Swim()
{
cout<<"Carp swims slow in the lake"<<endl;
}
};
int main()
{
const int ARRAY_AIZE=4;
Fish* myFishes[ARRAY_AIZE]={NULL};
myFishes[0]=new Tuna();
myFishes[1]=new Carp();
myFishes[2]=new Tuna();
myFishes[3]=new Carp();
Fish* myNewFishes[ARRAY_AIZE];
for(int Index=0;Index<ARRAY_AIZE;++Index)
myNewFishes[Index]=myFishes[Index]->Clone();
for(int Inde=0;Inde<ARRAY_AIZE;++Inde)
myNewFishes[Inde]->Swim();
for(int Ind=0;Ind<ARRAY_AIZE;++Ind)
{
delete myFishes[Ind];
delete myNewFishes[Ind];
}
return 0;
}
以上这个函数是可以通过编译的。但是一点击运行就报错了!unresolved external symbol "public: virtual void __thiscall Fish::Swim(void)" (?Swim@Fish@@UAEXXZ
fatal error LNK1120: 1 unresolved externals
求C++专家级的人士来解答!
感激不敬啊! 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询