#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);的参数加个*就解决了。
阅读(765) | 评论(0) | 转发(0) |