I have an issue that is already known in the community (one of the most complete answers can be found here), but I would like to know if there is a way to make compiler understand that you want to access base template members without needing to use typedef
or this
as below:
#include <iostream>
template<typename T>
struct Base{
T a;
T a2;
};
template<typename T1, typename T2>
struct Derived : Base<T2>{
T2 b;
void member_fnc();
};
template<typename T1, typename T2>
void Derived<T1,T2>::member_fnc(){
typedef Base<T2> base;
std::cout << "a = " << base::a << std::endl; // or this->a;
std::cout << "a2 = " << base::a2 << std::endl; // or this->a2;
std::cout << "b = " << b << std::endl;
}
int main(){
Derived<int,double> der1;
der1.a = 1;
der1.a2 = 2;
der1.b = 1.1;
der1.member_fnc();
}
I have this feeling that there should be a way to say compiler you want to access base template Base<T2>
without having to type it or including using
for every member you want to access, as you can unnest namespaces using using
keyword, but I couldn't find so far. Is it possible, at all?