A
Alessandro [AkiRoss] Re
Hello there,
I was trying this code:
#include <iostream>
template <typename T>
struct Base {
protected:
T value;
};
template <typename T>
struct Derived: public Base<T> {
void set(const T &d) {
this->value = d; // Must be referred using this
}
void get() {
//std::cout << "Value: " << value << std::endl; // ERROR
}
};
int main() {
Derived<int> d;
d.set(5);
d.get();
}
In the Derived::get() method, g++ tells me that value isn't in that
scope. While in set() it is, because I'm accessing it using the this
pointer.
Why is it necessary? It isn't required if the classes aren't
templates.
Thanks
I was trying this code:
#include <iostream>
template <typename T>
struct Base {
protected:
T value;
};
template <typename T>
struct Derived: public Base<T> {
void set(const T &d) {
this->value = d; // Must be referred using this
}
void get() {
//std::cout << "Value: " << value << std::endl; // ERROR
}
};
int main() {
Derived<int> d;
d.set(5);
d.get();
}
In the Derived::get() method, g++ tells me that value isn't in that
scope. While in set() it is, because I'm accessing it using the this
pointer.
Why is it necessary? It isn't required if the classes aren't
templates.
Thanks