首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ STL解决方法

2013-10-07 
C++STLvoid CReverse_IT::AutoPrint(int num){coutAutonum}void CReverse_IT::Print(){vector

C++ STL

void CReverse_IT::AutoPrint(int num)
{
cout<<"Auto"<<num<<"  ";
}

void CReverse_IT::Print()
{
vector<int> coll;
for (int i = 1; i < 10; i++)
{
coll.push_back(i * 5);
}

for_each(coll.begin(), coll.end(), AutoPrint);
cout<<endl;
}


函数调用缺少参数列表 c++ stl
[解决办法]
std::for_each(coll.begin(), coll.end(), std::bind1st(std::mem_ptr(&CReverse_IT::AutoPrint), this));
[解决办法]

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

class Test
{
public:

void AutoPrint(int num)
{
std::cout << num << " ";
}

void Print()
{
std::vector<int> coll;
for (int i = 0; i < 10; i++)
coll.push_back(i);

std::for_each(coll.begin(), coll.end(), std::bind1st(std::mem_fun(&Test::AutoPrint), this));
}
};

int main(void)
{
Test test;
test.Print();
return 0;
}

热点排行