Возможный дубликат:
Как определить функцию шаблона в классе шаблона вне определения класса?
Я борюсь с синтаксисом для случая, когда у меня есть функция члена шаблона в классе шаблона:
template <typename T> class Foo
{
void Bar(const T * t);
template <typename T2> void Bar(const T2 * t);
};
template <typename T> void Foo<T>::Bar(const T * t)
{
// ... no problem ...
}
template <typename T> void Foo<T>::Bar<typename T2>(const T2 * t)
{
// ... this is where I'm tearing my hair out ...
}
Первая функция-член отлично, но функция-член шаблона, которая обрабатывает типы, отличные от базового типа класса шаблона, - это то, где у меня возникают проблемы. В приведенном выше случае я получаю следующие ошибки:
template_problem.cpp:12: error: parse error in template argument list
template_problem.cpp:12: error: expected ‘,’ or ‘...’ before ‘*’ token
template_problem.cpp:12: error: ISO C++ forbids declaration of ‘T2’ with no type
template_problem.cpp:12: error: template-id ‘Bar<<expression error> >’ in declaration of primary template
template_problem.cpp:12: error: prototype for ‘void Foo<T>::Bar(int)’ does not match any in class ‘Foo<T>’
template_problem.cpp:4: error: candidates are: template<class T> template<class T2> void Foo::Bar(const T2*)
template_problem.cpp:7: error: void Foo<T>::Bar(const T*)
template_problem.cpp:12: error: template definition of non-template ‘void Foo<T>::Bar(int)’
и я также пробовал все другие варианты синтаксиса, которые я могу придумать для версии шаблона Bar
.