微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C的哪些特性让模板类在没有模板参数的情况下引用自己?

鉴于:
template <typename T>
class C {
    C & operator ++ () { ... }
};

为什么/如何允许C声明类型C的变量和函数而不是命名C< T>?在使用许多参数来模拟“自我类型”不方便的模板之前,我还没有真正考虑过它.

我应该知道这有什么怪癖吗?

解决方法

[n3290: 14.6.1/1]: Like normal (non-template) classes,class
templates have an injected-class-name (Clause 9)
. The
injected-class-name can be used as a template-name or a type-name.
When it is used with a template-argument-list,as a
template-argument for a template template-parameter,or as the final identifier in the elaborated-type-specifier of a friend class
template declaration,it refers to the class template itself.
Otherwise,it is equivalent to the template-name followed by the
template-parameters of the class template enclosed in <>.

表面上看,它只是一个方便的功能.

原文地址:https://www.jb51.cc/c/111620.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐