From the question:
Proper use of this->
The answer states that -> can be used
...in a template, in order to force the following symbol to be dependent—in this latter use, it is often unavoidable.
What does this mean what what would a good example of this use be? I don't quite what "dependent" means in this context, but it sounds like a useful trick.
Posted in other question:
template <class T>
struct foo : T {
void bar() {
x = 5; // doesn't work
this->x = 5; // works - T has a member named x
}
};
Without this->
compiler doesn't know x
is a (inherited) member.
Similar to use of typename
and template
inside template code:
template <class T, class S>
struct foo : T {
typedef T::ttype<S>; // doesn't work
typedef typename T::template ttype<S> footype; // works
};
It's silly and somewhat unnecessary, but you still gotta do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With