A
avasilev
HI all,
Can anyone tell me why this c ode does not compile on MSVC2008, but
compiles fine with GCC4. Are there any differences related to function
pointer template arguments for class templates and func templates?
template <typename Sig>
struct FuncSig;
template<typename RV, typename A1>
struct FuncSig<RV(A1)>
{ typedef RV(*Type)(A1); };
//Class template with the help of the signature class
template <typename Sig, typename FuncSig<Sig>::Type Func>
class Test{};
//function template with the help of the signature class
template <typename Sig, typename FuncSig<Sig>::Type Func>
int TestFunc()
{ return 123; }
//some random fucntion to pass as a pointer
int func(char a)
{
return 5;
}
Test<int(char), &func> f; //compiles as expected
int main()
{
//compiles on GCC, but fails on MSVC2008, with error messge:
//templateFuncAndClassArgValidity.cpp(27) : error C2975: 'Func' :
invalid template argument for //'TestFunc', expected compile-time
constant expression
// templateFuncAndClassArgValidity.cpp(13) : see declaration of
'Func'
TestFunc<int(char), &func>();
}
Can anyone tell me why this c ode does not compile on MSVC2008, but
compiles fine with GCC4. Are there any differences related to function
pointer template arguments for class templates and func templates?
template <typename Sig>
struct FuncSig;
template<typename RV, typename A1>
struct FuncSig<RV(A1)>
{ typedef RV(*Type)(A1); };
//Class template with the help of the signature class
template <typename Sig, typename FuncSig<Sig>::Type Func>
class Test{};
//function template with the help of the signature class
template <typename Sig, typename FuncSig<Sig>::Type Func>
int TestFunc()
{ return 123; }
//some random fucntion to pass as a pointer
int func(char a)
{
return 5;
}
Test<int(char), &func> f; //compiles as expected
int main()
{
//compiles on GCC, but fails on MSVC2008, with error messge:
//templateFuncAndClassArgValidity.cpp(27) : error C2975: 'Func' :
invalid template argument for //'TestFunc', expected compile-time
constant expression
// templateFuncAndClassArgValidity.cpp(13) : see declaration of
'Func'
TestFunc<int(char), &func>();
}