Частичная специализация шаблона
От: Andrew_manik Беларусь  
Дата: 09.12.10 12:40
Оценка:
Как правильно выполнить частичную специализацию метода для шаблона класса?

template <typename T1, typename T2>
class MyClass {
    double foo(T1 a, T2 b);
};

template <>
double MyClass<float, int>::foo(float a, int b) {   // OK
    return (double)a+b;
}

template <typename T1>
double MyClass<T1, short>::foo(T1 a, short b) {
    return (double)(a*b);
}
// MSVS 2005:
// error C2244: 'MyClass<T1,T2>::foo' : unable to match function definition to an existing declaration
// see declaration of 'MyClass<T1,T2>::foo'

// Intel C++ 11.1
// error: template argument list must match the parameter list
// double MyClass<T1, short>::foo(T1 a, short b) {
//        ^

// http://www.comeaucomputing.com/tryitout/
// "ComeauTest.c", line 21: error: template argument list must match the parameter list
//   double MyClass<T1, short>::foo(T1 a, short b) {
//          ^
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.