C++ 多态方面问题
#include<iostream>using namespace std;
class Fish
{
public:
virtual Fish* Clone()= 0;
virtual void Swim() = 0;
virtual ~Fish();
};
class Tuna:public Fish
{
public:
Fish* Clone() override
{
return new Tuna(*this);
}
void Swim()override final
{
cout<<"Tuna swims fast in the sea"<<endl;
}
};
class BluefinTuna final:public Tuna
{
public:
Fish* Clone() override
{
return new BluefinTuna(*this);
}
//cannot override Tuna::Swim as it is"final" in Tuna
};
class Carp final:public Fish
{
Fish* Clone() override
{
return new Carp(*this);
}
void Swim() override final
{
cout<<"Carp swims slow in the lake"<<endl;
}
};
int main()
{
const int ARRAY_SIZE = 4;
Fish*myFishes[ARRAY_SIZE] = {NULL};
myFishes[0] = new Tuna();
myFishes[1] = new Carp();
myFishes[2] = new BluefinTuna();
myFishes[3] = new Carp();
Fish*myNewFishes[ARRAY_SIZE];
for(int index = 0;index<ARRAY_SIZE;++index)
myNewFishes[index] = myFishes[index]->Clone();
//invoke a virtual method to check
for(int index = 0;index < ARRAY_SIZE;++index)
myNewFishes[index]->Swim();
//memory cleanup
for(int index = 0; index<ARRAY_SIZE;++index)
{
delete myFishes[index];
delete myNewFishes[index];
}
return 0;
} 这个是编译器出现的报错,请教一下大神,这是编译器告诉我,目前编译器的版本不支持C++2011标准码?如果是,怎么解决啊?是去官网更新,还是自己设置一下?上次也是百度查了一下,设置,然后编译器直接就不编译了,虽然没有出现报错,我用的是DEV-C++5.11这个编译器。谢谢各位大神!!!