百思不得其解的问题
#include <iostream>
#include <list>
using namespace std;
class CAnimal
{
public:
CAnimal(){};
virtual ~CAnimal(){};
virtual void Sound()
{
cout<<"animal sound\n";
}
};
class CDog : public CAnimal
{
public:
CDog(){};
~CDog(){};
virtual void Sound()
{
cout<<"dog sound\n";
}
};
class CCat : public CAnimal
{
public:
CCat(){};
~CCat(){};
virtual void Sound()
{
cout<<"cat sound\n";
}
};
int main()
{
list<CAnimal*> animalList;
CAnimal a1;
CAnimal a2;
CAnimal a3;
CDog d1;
CDog d2;
CDog d3;
CCat c1;
CCat c2;
CCat c3;
CCat c4;
animalList.push_back( &d1 );
animalList.push_back( &a2 );
animalList.push_back( &d3 );
animalList.push_back( &c3 );
animalList.push_back( &c4 );
animalList.push_back( &d2 );
animalList.push_back( &c1 );
animalList.push_back( &a3 );
animalList.push_back( &c2 );
animalList.push_back( &a1 );
for ( list<CAnimal*>::iterator it = animalList.begin(); it != animalList.end(); ++it )
{
it->Sound();
}
}
1>d:\working\test\test\test.cpp(36) : error C2839: 重载的“operator ->”的无效返回类型“CAnimal **”
1>d:\working\test\test\test.cpp(36) : error C2039: “CAnimal”: 不是“std::list<_Ty>::_Iterator<_Secure_validation>”的成员
#include <list>
using namespace std;
class CAnimal
{
public:
CAnimal(){};
virtual ~CAnimal(){};
virtual void Sound()
{
cout<<"animal sound\n";
}
};
class CDog : public CAnimal
{
public:
CDog(){};
~CDog(){};
virtual void Sound()
{
cout<<"dog sound\n";
}
};
class CCat : public CAnimal
{
public:
CCat(){};
~CCat(){};
virtual void Sound()
{
cout<<"cat sound\n";
}
};
int main()
{
list<CAnimal*> animalList;
CAnimal a1;
CAnimal a2;
CAnimal a3;
CDog d1;
CDog d2;
CDog d3;
CCat c1;
CCat c2;
CCat c3;
CCat c4;
animalList.push_back( &d1 );
animalList.push_back( &a2 );
animalList.push_back( &d3 );
animalList.push_back( &c3 );
animalList.push_back( &c4 );
animalList.push_back( &d2 );
animalList.push_back( &c1 );
animalList.push_back( &a3 );
animalList.push_back( &c2 );
animalList.push_back( &a1 );
for ( list<CAnimal*>::iterator it = animalList.begin(); it != animalList.end(); ++it )
{
it->Sound();
}
}
1>d:\working\test\test\test.cpp(36) : error C2839: 重载的“operator ->”的无效返回类型“CAnimal **”
1>d:\working\test\test\test.cpp(36) : error C2039: “CAnimal”: 不是“std::list<_Ty>::_Iterator<_Secure_validation>”的成员
...全文
相关推荐
百思不得其解API文档
**简介**:这部分简要介绍API的功能、目的以及它能解决的问题。在“百思不得其解API”中,可能提供了一个概述,解释了API的核心价值和适用场景。2.
easyui combotree加载静态数据问题(选不上)解决方法
在今天的开发中遇到一个奇怪的问题。虽然已经被我解决但还是百思不得其解,决定记录一下,看看有没有大神能给我答案。问题重现:由于我有4个combotree需要加载数据,但是我又不想每次初始化一个combo
示波器测量应用时的一个问题
初以为是电路板设计问题,看原理图也没发现明显错误,百思不得其解中。后借出差机会面看,方醒悟之。 前几日
HTML5中图片之间的缝隙完美解决方法
最近做h5的项目,碰到了一个百思不得其解的问题,几个img标签中间有大约3px的空隙 ,效果非常不好,纠结了半天终于解决了,下面小编给大家分享HTML5中图片之间的缝隙完美解决方法,需要的的朋友参考下
严蔚敏版数据结构习题集部分解析(C语言版)
还在为习题集的问题百思不得其解吗,来看看这个吧或许能帮的上你。


