0

I have the following problem, and it's rather annoying. I tried it on two compilers and it seems to be normal. Is there any way to avoid qualifying the parent/base class every time to access members?

#include <iostream>

template <typename T, typename U, typename V>
struct MyBase
{
    int baseMember;
    void baseFunction() { std::cout << "Hey"; }

    struct base_internal_struct { static inline int member; };
};

template <typename T, typename U, typename V>
struct MyDerived : public MyBase<T, U, V>
{
    int func() {
        std::cout << baseMember;  // Identifier not found
        std::cout << MyBase<T, U, V>::baseMember; // OK

        std::cout << base_internal_struct::member; // Identifier not found
        std::cout << MyBase<T, U, V>::base_internal_struct::member; // OK
        
        baseFunction(); // Identifier not found
        std::cout << MyBase<T, U, V>::baseFunction(); // OK

    }
};

int main()
{

}
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
  • You can also qualify with `MyDerived::` itself. Or you can do `using self = MyDerived;` and then use `self::`. The `::` is key, it makes it a dependent name. – rustyx Apr 05 '21 at 11:13
  • @rusty So it doesn't matter whether I do Base::baseFunction() or Derived::baseFunction() ? Interesting. – Zebrafish Apr 05 '21 at 17:37

0 Answers0