简体   繁体   中英

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.

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. 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

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. Forward declarations of nested classes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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