谁知道STL中mem_fun函数怎麽用啊?请指教!

lwg7603 2002-06-14 08:52:12
如题!
...全文
45 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2002-06-16
  • 打赏
  • 举报
回复
The following code can be build with VC.net, but it is not compatible with VC6.0, maybe there is something wrong with VC6.0 STL.#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
struct B {
virtual void print() = 0;
};

struct D1 : public B {
void print() { cout << "I'm a D1" << endl; return ; }
};

struct D2 : public B {
void print() { cout << "I'm a D2" << endl;return ; }
};

int main()
{
vector<B*> V;

V.push_back(new D1);
V.push_back(new D2);
V.push_back(new D2);
V.push_back(new D1);

for_each(V.begin(), V.end(), mem_fun(&B::print));
return 0;
}

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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