已经特化的成员函数特化 class
member function specialization of an already specialized class
我正在努力解决以下问题。基本上我有一个模板结构和一个专业化。
template<class T>
struct A
{
};
// Specialization of A for int
template<>
struct A<int>
{
template<class B>
void f(B b)
{
// Do stuff
}
};
是否可以专精A::f?
类似于:
template<>
template<>
void A<int>::f<double>(double b)
{
// do stuff
}
是的,但你只需要一个template<>
(A<int>
在这里已经完全特化了,成员函数只定义在特化A<int>
中,而不是在主模板中)
template<>
void A<int>::f<double>(double b)
{
std::cout << "specialization" << std::endl;
}
我正在努力解决以下问题。基本上我有一个模板结构和一个专业化。
template<class T>
struct A
{
};
// Specialization of A for int
template<>
struct A<int>
{
template<class B>
void f(B b)
{
// Do stuff
}
};
是否可以专精A::f?
类似于:
template<>
template<>
void A<int>::f<double>(double b)
{
// do stuff
}
是的,但你只需要一个template<>
(A<int>
在这里已经完全特化了,成员函数只定义在特化A<int>
中,而不是在主模板中)
template<>
void A<int>::f<double>(double b)
{
std::cout << "specialization" << std::endl;
}