L
linarin
#include <iostream>
using namespace std;
typedef bool (*CallableFunction)(int argc,char* argv[]);
void DefineMyFunction(const char* name,CallableFunction func){
//here do the define action.
}
template<typename R,typename A,R (*pFunc)(A)>
bool CallableFunctionProxy(int argc,char* argv[]){
A a = A(); // this is demo only
pFunc(a);
return true;
}
template<typename R,typename A>
void Def(const char* name,R (*pFunc)(A)){
DefineMyFunction(name,CallableFunctionProxy<R,A,pFunc>);
}
int alert(int){
cout << "From alert" << endl;
return 0;
}
int main(int argc,char* argv[])
{
CallableFunctionProxy<int,int,alert>(argc,argv);
//Def("alert",alert); //error here
return 0;
}
this program compile and execute as respected.
but when I uncomment the line marked with "error here" in function
"main" the following compile error occur, could any one known what is
error:
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:29: instantiated from
here
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: no matches
converting function `CallableFunctionProxy' to type `bool (*)(int,
char**)'
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:10: error: candidates
are: template<class R, class A, R (*pFunc)(A)> bool
CallableFunctionProxy(int, char**)
:: === Build finished: 8 errors, 1 warnings ===
using namespace std;
typedef bool (*CallableFunction)(int argc,char* argv[]);
void DefineMyFunction(const char* name,CallableFunction func){
//here do the define action.
}
template<typename R,typename A,R (*pFunc)(A)>
bool CallableFunctionProxy(int argc,char* argv[]){
A a = A(); // this is demo only
pFunc(a);
return true;
}
template<typename R,typename A>
void Def(const char* name,R (*pFunc)(A)){
DefineMyFunction(name,CallableFunctionProxy<R,A,pFunc>);
}
int alert(int){
cout << "From alert" << endl;
return 0;
}
int main(int argc,char* argv[])
{
CallableFunctionProxy<int,int,alert>(argc,argv);
//Def("alert",alert); //error here
return 0;
}
this program compile and execute as respected.
but when I uncomment the line marked with "error here" in function
"main" the following compile error occur, could any one known what is
error:
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:29: instantiated from
here
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: `pFunc' is
not a valid template argument
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: it must be
the address of a function with external linkage
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:18: error: no matches
converting function `CallableFunctionProxy' to type `bool (*)(int,
char**)'
D:\Program\CodeBlocks\Projects\firstCpp\main.cpp:10: error: candidates
are: template<class R, class A, R (*pFunc)(A)> bool
CallableFunctionProxy(int, char**)
:: === Build finished: 8 errors, 1 warnings ===