#include <cstdlib>
template<class A> struct Foo
{
template<class B> static bool Bar();
};
template<class B> template<class A> bool Foo<A>::Bar<B>()
{
return true;
}
int main()
{
bool b = Foo<int>::Bar<long>();
b;
}
Это приводит к ошибке компоновщика:
main.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl Foo<int>::Bar<long>(void)" (??$Bar@J@?$Foo@H@@SA_NXZ) referenced in function main
Мне нужно определить эту функцию-член вне объявления шаблона класса.Другими словами, я не могу этого сделать:
#include <cstdlib>
template<class A> struct Foo
{
template<class B> static bool Bar()
{
return true;
}
};
int main()
{
bool b = Foo<int>::Bar<long>();
b;
}
Что мне не хватает?Как я могу определить этот шаблон функции-члена?Какой синтаксис нужен?
Примечание: я использую MSVC 2008, на случай, если это уместно.
РЕДАКТИРОВАТЬ
Первое, что я попытался, - это изменить порядок * 1014.* и template<class B>
:
#include <cstdlib>
template<class A> struct Foo
{
template<class B> static bool Bar();
};
template<class A> template<class B> bool Foo<A>::Bar<B>()
{
return true;
}
int main()
{
bool b = Foo<int>::Bar<long>();
b;
}
Это привело к ошибке компилятора:
.\main.cpp(11) : error C2768: 'Foo<A>::Bar' : illegal use of explicit template arguments
В закрывающей скобке определения для функции Bar
.