根据这个网站
http://www.cplusplus.com/reference/std/functional/unary_function/
Run Code Online (Sandbox Code Playgroud)
这段代码应该有效
#include <iostream>
#include <functional>
using namespace std;
struct isdigit : public unary_function<char,bool>{
bool operator() (char a){ return (a>='0' && a<='9');}
};
int main(){
isdigit myobject;
isdigit::argument_type input;
isdigit::result_type result;
cout<<"please enter char";
cin>>input;
result=myobject(input);
cout<<"char"<<input<<"is "<<(result?"digit":"word")<<"\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但它显示某处支架错过但在哪里?
Configuration: Debug Win32 ------
1> function_in_c++.cpp
1>c:\users\david\documents\visual studio 2010\projects\functions_in_c++\function_in_c++.cpp(12): error C2146: syntax error : missing ';' before identifier 'object'
1>c:\users\david\documents\visual studio 2010\projects\functions_in_c++\function_in_c++.cpp(12): warning C4551: function call missing argument list
1>c:\users\david\documents\visual studio 2010\projects\functions_in_c++\function_in_c++.cpp(12): error C2065: 'object' : undeclared identifier
1>c:\users\david\documents\visual studio 2010\projects\functions_in_c++\function_in_c++.cpp(17): error C3861: 'object': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
210 次 |
| 最近记录: |