I am trying to specialize this template method 'he' but couldn't compile. How to do it right?
#pragma once
template<typename A, typename B>
class template_test
{
public:
template_test();
~template_test();
template<typename C>
void he(C gg);
};
template<typename A, typename B>
template<typename C>
void template_test<A, B>::he( C gg )
{
}
template<typename A, typename B>
template<>
void template_test<A, B>::he( int gg )
{
}
error C1506: unrecoverable block scoping error
unable to match function definition to an existing declaration
You have specialize the class also. You cannot just specialize only the member:
template<>
template<>
void template_test<int, int>::he<int>( int gg )
{
}
However, instead, I would just add an overload:
void he(int gg){}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.