模板问题,为什么在DEV里编译通不过

pusshi 2009-02-10 12:05:06
以上为什么在DEV里编译通不过
/背包类,由一个map记录武器名字和个数,vector记录武器属性; 
#include <iostream>
#include <string>
#include <vector>
#include <map>
//#include "F:\msdosd\gs\head\key.h"
using namespace std;
//typedef vector<Key> mups;
//typedef map<string,int> mup;
template <typename T>
class Bag//背包类
{
public:
Bag(){ }

bool del_bag(T& res);

void add_bag(T res);

bool emptybag(){return _bao.empty();}

void display_bag(bool shop=true);

vector<T> _baosu;//武器属性;
map<string, int> _bao ;//武器名字和个数


};

template <typename T>
bool Bag<T> ::del_bag(T& res)
{
vector<T>::iterator itis;
itis= _baosu.begin();
map<string, int>::iterator it;
it=_bao.find(res.first);
if( (it != _bao.end()) && (it->second >1) )
{
it->second--;
return true;
}

if( (it != _bao.end()) && (it->second =1) )
{
for(; itis != _baosu.end(); itis++)
{
if( itis->first == res.first)
{
_baosu.erase(itis);
_bao.erase(it);
return true;
}
}


}
return false;
}
template <typename T>
void Bag<T>::add_bag(T res)
{
map<string, int>::iterator it=_bao.begin();
it=_bao.find(res.first);
if(it != _bao.end())
{
it->second++;
}
else
{
_bao.insert(make_pair(res.first, 1));
_baosu.push_back(res);

}
}
template <typename T>
void Bag<T>::display_bag(bool shop)
{
map<string, int>::iterator it=_bao.begin();
vector<T>::iterator itis=_baosu.begin();
if(shop)
{

for(; it != _bao.end(); ++it)
{
cout<<it->first<<"\t数量:"<<it->second;
for(itis=_baosu.begin(); itis != _baosu.end();itis++)
{
if(itis->first == it->first)
{
cout<<"\t攻:"<<itis->second<<"\t";
}
}
}
cout<<endl;
}
else
{
for(; it != _bao.end(); ++it)
{
cout<<it->first<<"\t数量:"<<it->second;
for(itis=_baosu.begin(); itis != _baosu.end();itis++)
{
if(itis->first == it->first)
{
cout<<"\t攻:"<<itis->second<<"\t钱:"<<(it->second)*(itis->money)<<"\t";
}
}
}
cout<<endl;
}

}

int main()
{

return 0;
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pusshi 2009-02-10
  • 打赏
  • 举报
回复
dddddddddddddddddddddddddd
OenAuth.Net 2009-02-10
  • 打赏
  • 举报
回复
除了你的main少了半个大括号外,没发现别的VC6.0 GCC编译通过

int main()
{

return 0;

}
deerwin1986 2009-02-10
  • 打赏
  • 举报
回复
提示什么错误?
herman~~ 2009-02-10
  • 打赏
  • 举报
回复
太长 MARK

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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