Reputation: 602
The following code compiles fine using MSVC 2008. When you build GCC climbs a lot of errors (error after the code). What should be done to solve the error?
#define FORCE_INLINE inline
#define CREF(A) const A&
template <class F>
class RDOFunCalcStd: public RDOFunCalc
{
...
template <int paramCount>
FORCE_INLINE void calc(CREF(LPRDORuntime) pRuntime);
template <>
FORCE_INLINE void calc<1>(CREF(LPRDORuntime) pRuntime)
{
m_value = m_pFunction(getParam<F::arg1_type>(pRuntime, 0));
}
template <>
FORCE_INLINE void calc<2>(CREF(LPRDORuntime) pRuntime)
{
m_value = m_pFunction(getParam<F::arg1_type>(pRuntime, 0), getParam<F::arg2_type>(pRuntime, 1));
}
};
GCC provides the following errors:
error: too many template-parameter-lists
error: explicit specialization in non-namespace scope ‘class rdoRuntime::RDOFunCalcStd<F>’
error: variable or field ‘calc’ declared void
error: expected ‘;’ before ‘<’ token
error: expected ‘;’ before ‘template’
error: explicit specialization in non-namespace scope ‘class rdoRuntime::RDOFunCalcStd<F>’
error: variable or field ‘calc’ declared void
error: expected ‘;’ before ‘<’ token
Upvotes: 1
Views: 1385
Reputation: 299810
MSVC allows, as an extension, to specialize member functions right within the class, however this is not Standard.
If you wish to specialize member functions, you should do it at namespace level.
// note: use "inline" so that the linker merges multiple definitions
template <class F>
template <>
inline void RDOFunCalcStd<F>::calc<1>(LPRDORuntime const& pRuntime)
{
m_value = m_pFunction(getParam<typename F::arg1_type>(pRuntime, 0));
}
Also, FORCE_INLINE
is a bit erroneous, inline
is a hint, not an order to the compiler, so you're not forcing anything. And I dont quite see the point of CREF
either. You're not helping yourself using macros for anything, quite the contrary.
Upvotes: 5
Reputation: 1
Usually, GCC gives you line numbers. And perhaps you are using some C++ language features which are better supported in very recent GCC. Did you try GCC 4.6? And GCC can be given arguments (like here or more probably -std=c++0x
) governing the dialect it is accepting. I believe that recent GCC (ie g++
4.6) made a lot of efforts on language standard conformance. And GCC 4.6 can even give you column numbers in error messages.
Upvotes: 0