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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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++代码。我是一个有经验的java程序员,想学习C++。我已经阅读了一些关于模板的详尽文章,但是没有人回答我下面的模板规范是什么意思 template< template<template<class> class, class> class VisualOdometryTT, template<class> class NodeBuilderTT, class PoseGraphT> class VORosInterface{ ... }; 模板< 模板类VisualDometryTT, 模板类NodeBuilderTT, 类PoseGraphT> 类VORosInterface{…};_C++_Templates - Fatal编程技术网

C++;:模板<;类别>;什么意思? 我试图理解一些C++代码。我是一个有经验的java程序员,想学习C++。我已经阅读了一些关于模板的详尽文章,但是没有人回答我下面的模板规范是什么意思 template< template<template<class> class, class> class VisualOdometryTT, template<class> class NodeBuilderTT, class PoseGraphT> class VORosInterface{ ... }; 模板< 模板类VisualDometryTT, 模板类NodeBuilderTT, 类PoseGraphT> 类VORosInterface{…};

C++;:模板<;类别>;什么意思? 我试图理解一些C++代码。我是一个有经验的java程序员,想学习C++。我已经阅读了一些关于模板的详尽文章,但是没有人回答我下面的模板规范是什么意思 template< template<template<class> class, class> class VisualOdometryTT, template<class> class NodeBuilderTT, class PoseGraphT> class VORosInterface{ ... }; 模板< 模板类VisualDometryTT, 模板类NodeBuilderTT, 类PoseGraphT> 类VORosInterface{…};,c++,templates,C++,Templates,我不理解的部分是模板,我认为其中缺少一些类型规范。但是代码编译没有问题。使用NodeBuilderTT作为示例,因为它更容易: NodeBuilderTT是一个模板参数,它本身就是一个只有一个参数的模板——我们称之为Z 您可以选择正式命名Z,代码的编译方式与此相同: template<class Z> class NodeBuilderTT 但是,对于函数,您通常会在函数体内部使用名称x。对于模板,您不能在VORosInterface的定义中使用Z,因此命名它是绝对没有意义的,编写

我不理解的部分是
模板
,我认为其中缺少一些类型规范。但是代码编译没有问题。

使用
NodeBuilderTT
作为示例,因为它更容易:

NodeBuilderTT
是一个模板参数,它本身就是一个只有一个参数的模板——我们称之为
Z

您可以选择正式命名
Z
,代码的编译方式与此相同:

template<class Z> class NodeBuilderTT
但是,对于函数,您通常会在函数体内部使用名称
x
。对于模板,您不能在
VORosInterface
的定义中使用
Z
,因此命名它是绝对没有意义的,编写它是惯用的

template<class> class NodeBuilderTT
模板类NodeBuilderTT

我感谢K-ballo在这里帮助我澄清了这一记录。

搜索“模板参数”。即使你很想命名它,它也毫无意义,因为你不能使用它。谢谢你的解释!现在我明白了,但是我深入研究C++的时候,我更喜欢java:D@K-巴洛:你说如果我写了
模板类VORosInterface{…}
我不能在类主体中使用
t
作为类型参数?@peci1:确切地说,
t
在这里是没有意义的,因为参数采用的是类模板,而不是实例化的模板
T
是一个没有相应参数的参数。更接近的平行方式是使用指向函数的指针作为函数参数:在
void f(void(*ptr)(int n)){}
中,实际上不能使用
n
template<class> class NodeBuilderTT