T.62: Place non-dependent class template members in a non-templated base class
T.62:将非依赖类模板成员放入非模板基类中
Reason(原因)
Allow the base class members to be used without specifying template arguments and without template instantiation.
允许在不定义模板参数和不例示模板的情况下使用基类成员。
Example(示例)
template<typename T>
class Foo {
public:
enum { v1, v2 };
// ...
};
struct Foo_base {
enum { v1, v2 };
// ...
};
template<typename T>
class Foo : public Foo_base {
public:
// ...
};
A more general version of this rule would be "If a class template member depends on only N template parameters out of M, place it in a base class with only N parameters." For N == 1, we have a choice of a base class of a class in the surrounding scope as in T.61.
What about constants? class statics?
本规则的更普遍版是:如果模板类成员只依赖于M以外的N个模板参数,将其放入只包含N个参数的基类中。对于N==1的情况,我们可以选择外围作用域的某个类的基类,就像T.61那样。
常量该如何处理?静态成员呢?
Enforcement(实施建议)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有