Explicit specialization in non-namespace scope
VC++ is non-compliant in this case - explicit specializations have to be at namespace scope. C++03, §14.7.3/2:
An explicit specialization shall be declared in the namespace of which the template is a member, or, for member templates, in the namespace of which the enclosing class or enclosing class template is a member.
An explicit specialization of a member function, member class or static data member of a class template shall be declared in the namespace of which the class template is a member.
Additionally you have the problem that you can't specialize member functions without explicitly specializing the containing class due to C++03, §14.7.3/3, so one solution would be to let Verify()
forward to a, possibly specialized, free function:
namespace detail {
template <typename TL> void Verify (int, int[]) {}
template <> void Verify<int>(int, int[]) {}
}
template<typename T> class CConstraint {
// ...
template <typename TL> void Verify(int position, int constraints[]) {
detail::Verify<TL>(position, constraints);
}
};
GCC error: explicit specialization in non-namespace scope
You just have to move your specializations of the member templates outside of the class body.
class VarData
{
public:
template < typename T > bool IsTypeOf (int index) const
{
return IsTypeOf_f<T>::IsTypeOf(this, index);
}
};
template <> bool VarData::IsTypeOf < int > (int index) const
{
return false;
}
template <> bool VarData::IsTypeOf < double > (int index) const
{
return false;
}
Explicit specialization in non-namespace scope error... Desperately need help
In this case overloading should suffice instead of specializing:
template <typename T> class Data_T
{
public:
template<typename U> static bool IsEqual(const U& a, const U& b)
{
return a == b;
}
static bool IsEqual(const MyData& a, const MyData& b)
{
return MyDataTypeIsEqual (a, b);
}
template<typename U> bool IsRangeEqual(const U& a, const U& b, const U& delta)
{
return (a >= b) ? (a - b <= delta) : (b - a <= delta);
}
bool IsRangeEqual(const MyData & a, const MyData & b, const MyData & accuracy)
{
return MyDataTypeIsRangeEqual (a, b, accuracy);
}
};
Edit regarding update:
While for me the conversion from float
to float __vector__
already fails, you seem to have a typo of:
template<typename U> static bool IsEqual(const T& a, const T& b)
vs.:
template<typename U> static bool IsEqual(const U& a, const U& b)
I fixed the above code accordingly.
Related Topics
Are Child Processes Created with Fork() Automatically Killed When the Parent Is Killed
Linking a Shared Library with Another Shared Lib in Linux
Are Inner Classes in C++ Automatically Friends
C++ Function Pointer (Class Member) to Non-Static Member Function
Std::String::C_Str() and Temporaries
Are C++17 Parallel Algorithms Implemented Already
How to Run a Child Process That Requires Elevation and Wait
C++ Inline Member Function in .Cpp File
How to Embed a File into an Executable
What's This C++ Syntax That Puts a Brace-Surrounded Block Where an Expression Is Expected
About Binding a Const Reference to a Sub-Object of a Temporary
#Define Nominmax Using Std::Min/Max