Quantcast
Channel: Why do I have to access template base class members through the this pointer? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Why do I have to access template base class members through the this pointer?

$
0
0

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why?

template <typename T>class base {protected:    int x;};template <typename T>class derived : public base<T> {public:    int f() { return this->x; }};int main() {    derived<int> d;    d.f();    return 0;}

Viewing all articles
Browse latest Browse all 4

Trending Articles