Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 已经专门化的类的成员函数专门化_C++_Templates_Template Specialization - Fatal编程技术网

C++ 已经专门化的类的成员函数专门化

C++ 已经专门化的类的成员函数专门化,c++,templates,template-specialization,C++,Templates,Template Specialization,我正在努力解决以下问题。基本上我有一个模板结构和一个专门化 template<class T> struct A { }; // Specialization of A for int template<> struct A<int> { template<class B> void f(B b) { // Do stuff } }; 模板 结构A { }; //int的A的

我正在努力解决以下问题。基本上我有一个模板结构和一个专门化

template<class T>
struct A
  {
  };


// Specialization of A for int
template<>
struct A<int>
  {
    template<class B>
    void f(B b)
      {
      // Do stuff
      }
  };
模板
结构A
{
};
//int的A的特殊化
模板
结构A
{
模板
无效f(B)
{
//做事
}
};
有可能专门化A::f吗

比如:

template<>
template<>
void A<int>::f<double>(double b)
  {
  // do stuff
  }
模板
模板
空A::f(双b)
{
//做事
}

是,但您只需要一个
模板(
A
在这里已经完全专门化,成员函数只在专门化
A
中定义,而不在主模板中定义)

模板
空A::f(双b)
{

出于某种原因,我确信我需要两个模板thanks@user3770392不,因为上面已经明确专门化了
A
。您没有同时专门化
A
f
,因为
f
只在专门化
A
中定义,所以您只在
A
中专门化
f
。在本例中,您需要使用2
template
:,因为您要完全专门化模板类中的成员函数,所以需要同时专门化两者。
template<>
void A<int>::f<double>(double b)
{
    std::cout << "specialization" << std::endl;
}