简体   繁体   English

C++ 继承模板 class 并具有自己的类内结构

[英]C++ inherit template class with its own in-class struct

template <typename Foo>
class A{

};

class B : A<B::Bar>{
    struct Bar{

    };
};

I wonder how could I do something like this, or it's the only way to move struct Bar outside the class B.我想知道我怎么能做这样的事情,或者这是将 struct Bar 移到 class B 之外的唯一方法。

You simply can't do it!你根本做不到!

You can not use an unknown type as template parameter and you can't forward a nested class type.不能使用未知类型作为模板参数,也不能转发嵌套的 class 类型。 Both together makes it impossible to do what you like to do.两者加在一起就不可能做你喜欢做的事。

About forwarding a nested class declaration see here: forward declaration of nested class关于转发嵌套的 class 声明,请参见此处: 嵌套 class 的转发声明

There was already a proposal to add such thing to C++, but I think it is not part of the standard even not in C++20.已经有人提议在 C++ 中添加这样的东西,但我认为即使在 C++20 中也不是标准的一部分。 Forward declarations of nested classes 嵌套类的前向声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM