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

关于term does not evaluate to a function taking 一 arguments

2012-09-13 
关于term does not evaluate to a function taking 1 arguments请求高手帮助,关于使用stl,已经一头雾水了,

关于term does not evaluate to a function taking 1 arguments
请求高手帮助,关于使用stl,已经一头雾水了,以下是我的code,请求解错。
#include<string>
#include<iostream>
#include "Cards.h"
#include <vector>
#include <algorithm>

using namespace std;

struct F2
{void for_each_3 (string l,Cards &vec_card,vector<Cards> &vec_c)
{vec_card.set_label(l);
 vec_card.set_visit(0);
  vec_c.push_back(vec_card);}};

struct F1
 {void for_each_1 (string s,vector<string> vec_label,Cards &vec_card)
{vec_card.set_suit(s);
 for_each(vec_label.begin(),vec_label.end(),F2());
}};

void initiate(const vector<string> vec_suit,const vector<string> vec_label,vector<Cards> &vec_card);
int main()

{Cards vec_c;
 vector<Cards> vec_card;
 vector<string> vec_suit;
 vector<string> vec_label;

 //initiate(vec_suit,vec_label, vec_card);
}

void initiate(vector<string>& vec_suit,vector<string>& vec_label,Cards &vec_c)
{vec_suit.push_back("Club");
 vec_suit.push_back("Diamonds");
 vec_suit.push_back("Heart");
 vec_suit.push_back("Spade");
 vec_label.push_back("Ace");
 vec_label.push_back("King");
 vec_label.push_back("Queen");
 vec_label.push_back("Jack");
 vec_label.push_back("10");
 vec_label.push_back("9");
 vec_label.push_back("8");
 vec_label.push_back("7");
 vec_label.push_back("6");
 vec_label.push_back("5");
 vec_label.push_back("4");
 vec_label.push_back("3");
 vec_label.push_back("2");
for_each(vec_suit.begin(),vec_suit.end(),F1());};

错误如下:给的很详细,就是没明白。。。。。
1>------ Build started: Project: Assignment3, Configuration: Debug Win32 ------
1>Compiling...
1>assignment3.cpp
1>d:\program files\microsoft visual studio 9.0\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
1> e:\c++\practice\assignment3\assignment3\assignment3\assignment3.cpp(20) : see reference to function template instantiation '_Fn1 std::for_each<std::_Vector_const_iterator<_Ty,_Alloc>,F2>(_InIt,_InIt,_Fn1)' being compiled
1> with
1> [
1> _Fn1=F2,
1> _Ty=std::string,
1> _Alloc=std::allocator<std::string>,
1> _InIt=std::_Vector_const_iterator<std::string,std::allocator<std::string>>
1> ]
1>d:\program files\microsoft visual studio 9.0\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
1> e:\c++\practice\assignment3\assignment3\assignment3\assignment3.cpp(54) : see reference to function template instantiation '_Fn1 std::for_each<std::_Vector_iterator<_Ty,_Alloc>,F1>(_InIt,_InIt,_Fn1)' being compiled
1> with
1> [
1> _Fn1=F1,
1> _Ty=std::string,
1> _Alloc=std::allocator<std::string>,
1> _InIt=std::_Vector_iterator<std::string,std::allocator<std::string>>
1> ]
1>Build log was saved at "file://e:\Tiberwal C++\practice\Assignment3\Assignment3\Assignment3\Debug\BuildLog.htm"
1>Assignment3 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========






 


[解决办法]
struct F2 


{
void operator ()(string str) //mark 定义函数对象
{
}

void for_each_3 (string l,Cards &vec_card,vector <Cards> &vec_c) 
{
vec_card.set_label(l); 
vec_card.set_visit(0); 
vec_c.push_back(vec_card);
}
}; 

struct F1 
{
void operator ()(string str) //mark 定义函数对象
{
}

void for_each_1 (string s,vector <string> vec_label,Cards &vec_card) 
{
vec_card.set_suit(s); 
for_each(vec_label.begin(),vec_label.end(),F2()); 
}
};

热点排行