标签:amp ack out blog 错误 system div main opera
#include<iostream>
using namespace std;
#include"algorithm"
#include"functional"
#include"vector"
//类模版函数
template <typename T>
class Obj
{
public:
Obj()
{
n = 0;
}
void operator()(T & t)
{
n++;
cout << t << endl;
}
void PtintN()
{
cout << n << endl;
}
public:
int n;
};
//模板函数
template <typename T>
void FuncprintT( T &t1)
{
cout << t1 << endl;
}
//普通函数
void Funcprintt(int &t2)
{
cout << t2 << endl;
}
int main01()
{
int tem = 10;
Obj<int > o1;//类模版
o1(tem);
FuncprintT<int>(tem);
FuncprintT(tem);
return 0;
}
int main02()
{
vector<int > v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
for_each(v1.begin(), v1.end(), Obj<int>());
for_each(v1.begin(), v1.end(), FuncprintT<int>);
int tem2 = 10;
cout << " 这里是运用 函数对象作为for_each的第三个对象:\n";
Obj<int > otem;
for_each(v1.begin(), v1.end(), otem);//这里有疑问?遗留问题,不是每一个运算符重载都自动运行的
//for_each(v1.begin(), v1.end(), Obj<int > otem2); 这个为什么是错误的?
otem.PtintN();
return 0;
}
int main()
{
//main01();
main02();
system("pause");
}
标签:amp ack out blog 错误 system div main opera
原文地址:http://www.cnblogs.com/xiaochige/p/6901955.html