关于men_fun函数的,求达人解释

woshilajitaba 2011-04-23 10:51:18
class Employee
{
string first,last;
public:
Employee(const string& fn="John",const string& ln="Smith"):first(fn),last(ln){}
virtual void print() const
{
cout<<"First name:"<<first<<",Last name"<<last<<endl;
}
virtual ~Employee(){}
};

class Manager:public Employee
{
int level;
list<Employee*> subordinates;
public:
Manager(const string& fn="Ivan",const string& ln="Stedwick",int lvl=1):Employee(fn,ln),level(lvl){}
void print()
{
cout<<"Manager level:"<<level<<" ";
Employee::print();
cout<<"Supervises:"<<endl;
for_each(subordinates.begin(),subordinates.end(),std::mem_fun(&Employee::print));
cout<<endl<<endl;
}
void addstaff(Employee& staff)
{
subordinates.push_front(&staff);
}
void addstaff(Employee* staff)
{
subordinates.push_front(staff);
}
};


编译时总是有错,error C2664: 'mem_fun' : cannot convert parameter 1 from 'void (__thiscall Employee::*)(void) const' to 'void (__thiscall Employee::*)(void)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
有人能帮帮我么,我用const_cast试过,但都没成功
...全文
174 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bargio_susie 2011-04-23
  • 打赏
  • 举报
回复
没看出来有什么问题 ,报上编译器类型,版本
maoxing63570 2011-04-23
  • 打赏
  • 举报
回复
vs2010,vs2005都是没有鸭梨的
maoxing63570 2011-04-23
  • 打赏
  • 举报
回复
学STL还是就不要用vc6.0了,会死人的
woshilajitaba 2011-04-23
  • 打赏
  • 举报
回复
解决方法?
bdmh 2011-04-23
  • 打赏
  • 举报
回复
Employee(const string& fn="John",const string& ln="Smith"),这种构造函数不行,因为都是用了默认值,这样就无法与不带默认值的Employee()区分开了,所以你不要都设置成默认值参数,而且const传递,也要注意一下,传递时,要和const匹配
woshilajitaba 2011-04-23
  • 打赏
  • 举报
回复
估计是编译器的问题,为嘛在vc6.0不能用STL呢,还有,我在vc6.0下装boost就没装好过,难道非得用vs?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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