Можно создать дубликат:
Where and why do I have to put the “template” and “typename” keywords?вызова шаблона функции шаблона базового класса
Вот код:
template<typename T>
class base
{
public:
virtual ~base();
template<typename F>
void foo()
{
std::cout << "base::foo<F>()" << std::endl;
}
};
template<typename T>
class derived : public base<T>
{
public:
void bar()
{
this->foo<int>(); // Compile error
}
};
И, при запуске:
derived<bool> d;
d.bar();
я получаю следующие ошибки:
error: expected primary-expression before ‘int’
error: expected ‘;’ before ‘int’
Я знаю non-dependent names and 2-phase look-ups. Но, когда сама функция является функцией шаблона (функция foo<>()
в моем коде), я пробовал все обходные пути только для отказа.
спасибо! действительно спас мой бекон сегодня – Jacko