Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.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

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++ 通用编程中的关键字模板规范 #包括 命名空间oo{ 甲级{ 公众: 模板 static T get_value(){返回static_cast(55);} }; 模板 B类{ 公众: 静态双f(){return T::get_value();} }; } int main(int argc,char*argv[]) { 使用std::cout; 使用std::endl; cout_C++_Templates - Fatal编程技术网

C++ 通用编程中的关键字模板规范 #包括 命名空间oo{ 甲级{ 公众: 模板 static T get_value(){返回static_cast(55);} }; 模板 B类{ 公众: 静态双f(){return T::get_value();} }; } int main(int argc,char*argv[]) { 使用std::cout; 使用std::endl; cout

C++ 通用编程中的关键字模板规范 #包括 命名空间oo{ 甲级{ 公众: 模板 static T get_value(){返回static_cast(55);} }; 模板 B类{ 公众: 静态双f(){return T::get_value();} }; } int main(int argc,char*argv[]) { 使用std::cout; 使用std::endl; cout,c++,templates,C++,Templates,这就是运行时的情况 static double f(){return T::template get_value<double>(); } 名称空间oo{ A类{ 公众: //模板//未替换为类型。 静态双get_value(){return static_cast(55);} }; //模板//未替换为类型。 B类{ 公众: 静态双f(){return oo::A::get_value/**/();} }; } int main(int argc,char*argv[]) { 使

这就是运行时的情况

static double f(){return T::template get_value<double>(); }
名称空间oo{
A类{
公众:
//模板//未替换为类型。
静态双get_value(){return static_cast(55);}
};
//模板//未替换为类型。
B类{
公众:
静态双f(){return oo::A::get_value/**/();}
};
}
int main(int argc,char*argv[])
{
使用std::cout;
使用std::endl;

cout原因是编译器如何解释该行,当您使用模板时,语法有多个可能的解释,请查看以下内容:

template <class T>
class foo
{
   //T will be valid in this scope.
};
静态双f()
{
返回T::获取_值();
}
在函数中,如何确定传递给B类的T参数有一个名为get_value的函数或一个名为get_value的数据成员?如果是第二种情况,则使用的运算符是lees than,在该成员和double之间,然后在double和()编译器的第一个假设是这些选项,如果你想告诉他这是一个带模板的函数(为了正确解释“
namespace oo{

  class A{  
  public:
   // template<typename T>  // T replaced with <double> type.
    static double get_value(){return static_cast<double>(55);}
  };

  //template <typename T=A> // T replaced with <oo::A> type.
  class B{
    public:
    static double f(){return oo::A::get_value/*<double>*/();}
  };

}

int main(int argc, char *argv[])
{
  using std::cout;
  using std::endl;

  cout << oo::B::f() << endl;

  return 0;
}
template <class T>
class foo
{
   //T will be valid in this scope.
};
static double f()
{
    return T::get_value < double > ();
}