Here is a testing snippet involving inheriting from template classes:
#include <iostream>
using namespace std;
template <typename T>
struct A {
T x;
};
template <typename T>
struct B : public A<T> {
B(T x, T y) : A<T>{ x }, y{ y } { }
T y;
};
template <typename T>
struct C : public B<T> {
C(T x, T y, T z) : B<T>{ x, y }, z{ z } { }
T z;
// when I typed `this->`, Intellisense didn't give me the option `x`,
// which is iherited from `A<T>` and should appear in the autocomplete pop-up.
// In contrast, `this->` did give the option `y`.
void test() { cout << this->x << ", " << this->y << ", " << z << endl; }
};
int main() {
C<int> c{ 1, 2, 3 };
c.test(); // prints out `1, 2, 3` as expected
return 0;
}
The code compiles and runs. But in void C<T>::test()
, when I tried to access the member x
defined in the indirect base class A<T>
using this
pointer, x
didn't show up in the Intellisense autocomplete pop-up. On the other hand, the directly inherited member y
did show-up.
I tested with VS2019 and VSCode+gcc, both of which gave similar results.
But I know that Intellisense is a very powerful engine, so I wonder if I'm doing inheritance from template classes correctly or not? If I'm wrong, what is the proper way?