Chinaunix首页 | 论坛 | 博客
  • 博客访问: 657487
  • 博文数量: 134
  • 博客积分: 3158
  • 博客等级: 中校
  • 技术积分: 1617
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-30 22:36
文章分类

全部博文(134)

文章存档

2012年(2)

2011年(28)

2010年(68)

2009年(35)

2008年(1)

我的朋友

分类: WINDOWS

2010-08-17 11:13:00

#include
#include
#include
#include
using namespace std;
//struct that behaves as a unary function
template
struct DisplayElement
{
 void operator()(const elementType & element) const
 {
  cout < }
};
template
void FuncDispalyElement(const elementType & element)
{
 cout<< element << ' ';
};
int main()
{
 vector vecIntegers;
 for (int nCount = 0; nCount <10; ++nCount)
 {
  vecIntegers.push_back(nCount);
 }
 list listChars;
 for (char nChar = 'a';nChar < 'k'; ++nChar)
 {
  listChars.push_back(nChar);
 }
 cout <<"Displaying the vector of inters:" << endl;
 //Display the array of integers
 for_each( vecIntegers.begin(),vecIntegers.end(),DisplayElement())
  ;
 std::list ::iterator iElementLocator;
 for( iElementLocator = listChars.begin();
 iElementLocator != listChars.end();
 ++iElementLocator)
  FuncDispalyElement(iElementLocator);
 for_each( listChars.begin(),listChars.end(),DisplayElement())
  ;
}
 
原来FuncDispalyElement(iElementLocator);的参数加个*就解决了。
阅读(725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~