-
2 votesanswersviews
在模板定义中要求typename的原因[重复]
可能重复:我必须在依赖名称上放置“template”和“typename”的位置和原因? 这是该问题的具体实例:Officially, what is typename for? 我问的具体原因是编译器不知道以下是一个类型: #include <set> #include <vector> template<typename T> // T is a... -
4 votesanswersviews
“typename”和“template”关键字:他们真的有必要吗?
在编译c模板代码时,此站点存在许多问题 . 解决此类问题的最常见方法之一是在程序代码的正确位置添加 typename (以及不常见的 template )关键字: template<typename T> class Base { public: typedef char SomeType; template<typename U> void S... -
2 votesanswersviews
C - 是否有任何要点使用<class T>而不是<typename T> [duplicate]
可能重复:模板中关键字'typename'和'class'的C差异 使用是否有任何意义/好处: <class T> 而不是: <typename T> 在C? -
0 votesanswersviews
C中的'typename'字[重复]
这个问题在这里已有答案: Where and why do I have to put the “template” and “typename” keywords? 6个答案 Officially, what is typename for? 7个答案 我正在阅读C代码,我在类定义的中间遇到了关键字 typename 的使用 . 这是类定义,关键字在受保护的部分中使用 . templ... -
28 votesanswersviews
将typename关键字与模板函数参数一起使用
在C中,需要 typename 关键字,因此编译器可以消除模板中嵌套类型和嵌套值之间的歧义 . 但是,在某些情况下,不存在歧义,例如派生类继承嵌套类类型时 . template <class T> class Derived : public T::type { }; 这里不需要 typename 关键字,实际上甚至不允许 . 这是有道理的,因为上下文消除了歧义 . 这里, T::t... -
0 votesanswersviews
调用模板函数,模板指针指向函数[关闭]
我的问题是我尝试调用我的模板函数test,它将指针指向另一个模板函数 . 因为你不能有模板指向函数,我通过在struct中包装这样的typedef指针来实现它(参见Template typedefs - What's your work around?) . 它's OK - I can call my template function by a pointer, but problem is ... -
950 votesanswersviews
我必须在何处以及为何要使用“模板”和“typename”关键字?
在模板中,我在哪里以及为什么必须在依赖名称上放置 typename 和 template ?究竟什么是依赖名称?我有以下代码: template <typename T, typename Tail> // Tail will be a UnionNode too. struct UnionNode : public Tail { // ... template<... -
0 votesanswersviews
如何确保模板中的typedef也被调用?
我正在使用SWIG为C#包装一个C类(PointMatcher.h) . 我使用 %template 指令将模板类具体化,如下所示: %include "../pointmatcher/PointMatcher.h" %template(PointMatcherFloat) PointMatcher<float>; 但是,事实证明模板 PointMatcher&... -
46 votesanswersviews
什么时候需要“typename”关键字? [重复]
可能重复:正式,什么是typename?我必须在哪里以及为什么要放置模板和typename关键字? 考虑以下代码: template<class K> class C { struct P {}; vector<P> vec; void f(); }; template<class K> void C<K>::f() {... -
28 votesanswersviews
为什么模板模板参数不允许参数列表后面的'typename'
模板模板typename? 在 template <template <typename> class T> 中使用 template template 语法时,需要使用关键字 class ,因为使用 typename 会产生以下错误: 错误:模板模板参数在参数列表后需要'class' 在声明模板参数的基本情况下,关键字 typename 和 class 在其他任何地方... -
952 votesanswersviews
我必须在何处以及为何要使用“模板”和“typename”关键字?
在模板中,我在哪里以及为什么必须在依赖名称上放置 typename 和 template ?究竟什么是依赖名称?我有以下代码: template <typename T, typename Tail> // Tail will be a UnionNode too. struct UnionNode : public Tail { // ... template<... -
0 votesanswersviews
奇怪的类型名称和构造函数在模板中
我试图理解C中的模板类 . 首先,我想了解这一行的含义: template <typename T, typename Ord = columns, typename All = abc::allocator<T,16> > class matrix 其中columns和allocator分别是struct和在其他地方定义的类(名称空间abc中的第二个) . 让我感到困扰... -
0 votesanswersviews
类模板交互
我实际上相当确定我的问题的答案可以在之前创建的一个线程中找到 . 特别是Where and why do I have to put the "template" and "typename" keywords?,它对模板/ typename消歧有很好的解释 . 然而,我不知所措,因为我实际上无法将概念扩展到我的代码,这些代码是彼此交互的类模板 . 在这个帖... -
952 votesanswersviews
我必须在何处以及为何要使用“模板”和“typename”关键字?
在模板中,我在哪里以及为什么必须在依赖名称上放置 typename 和 template ?究竟什么是依赖名称?我有以下代码: template <typename T, typename Tail> // Tail will be a UnionNode too. struct UnionNode : public Tail { // ... template<... -
952 votesanswersviews
我必须在何处以及为何要使用“模板”和“typename”关键字?
在模板中,我必须在哪里以及为什么要在依赖名称上放置 typename 和 template ?究竟什么是依赖名称?我有以下代码: template <typename T, typename Tail> // Tail will be a UnionNode too. struct UnionNode : public Tail { // ... template<... -
3 votesanswersviews
再次使用typename和template关键字
我已经仔细阅读了很多关于这个主题的答案,但是在非模板函数(嵌套模板类的成员)的范围内,当这两个关键字不需要这些关键字时,我无法弄清楚 . 我的参考编译器是GNU g 4.9.2和clang 3.5.0 . 它们在下面的代码中几乎没有什么不同,我把嵌入式注释试图解释会发生什么 . #include <iostream> // a simple template class with a...