gpt4 book ai didi

c++ - 结构后的尖括号

转载 作者:行者123 更新时间:2023-11-30 02:52:45 26 4
gpt4 key购买 nike

我无法理解 C++ 代码中的以下行:

template<class Variable> struct strVar< :: namespaceName::strVar2_<Variable>> : public trueType {};

struct strVar 后面的尖括号是什么意思?我以前从未听说过这种风格。

该行没有用我的编译器编译,但它来自一个正在运行的软件,所以它在某种意义上一定是正确的。

最佳答案

代码定义了类模板 strVar 的部分特化。在代码的前面某处,必须至少有一个主模板的声明:

template <class T> struct strVar;

然后,您发布的代码提供了一个定义,只要它的模板参数(对应于 T)恰好是类模板的特化,它就会用于 strVar ::namespaceName::strVar2_.

例子:

strVar<int> x;  // will use primary template
strVar<::namespaceName::strVar2_<int>> x; // will use the specialisation

关于c++ - 结构后的尖括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18637112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com