C++ `using {var}` is not a member of {child class} - when using `std::deque` in MSVC or Clang

Viewed 88

The code below gives the error error C2039: 'value_type': is not a member of 'Child_Container' on line 7. This happens in MSVC and Clang, but not with GCC. Thereby when using std::deque, but not std::set, std::vector. Does anyone know why? Thank you!

#include <deque>

template<typename T_Container>
struct _View
{
    using           NOPE = typename T_Container::value_type;
};

template<typename T_type, typename T_Self>
struct Base_Container
{
    using value_type = T_type;
    std::deque<_View<T_Self>>   _views;
};

struct Child_Container : public Base_Container<double, Child_Container>
{
    // using value_type = double; // Even with this line.
    using base = Base_Container<value_type, Child_Container>;
};

int main()
{
    return 0;
}
1 Answers

The variable here is simply whether std::deque requires its element type to be complete when it is instantiated. (Of course it must be complete when certain member functions are instantiated, but that’s separate.) If it does, you end up needing your value_type before it’s declared, which produces the error observed. C++17 requires that std::vector support incomplete types, but says nothing about std::deque, which is why this varies per standard library.

Related