May 28, 2018

[C++] is inherit const type valid?

Valid since while using typedef, i.e template<typename>
is really typedef, if the type alias is used as a type name, the c.v will be dropped.

[class.name]/5:
If a typedef-name that names a cv-qualified class type is used where a class-name is required, the cv-qualifiers are ignored.

struct base {
};

template<typename T>
struct inherit : T {
    using T::T;
};

int main() {
    inherit<base const>{};
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.