As in stl containers, why can't we access a typedef inside the class from the class instance? Is there a particular insight into this?
When value_type was a template parameter it could help making more general code if there wasn't the need to specify the template parameters as in vector::value_type
Example:
class T {
public:
typedef int value_type;
value_type i;
};
T t;
T::value_type i; // ok
t.value_type i; // won't work
The answer is use decltype
to get the class first. E.g.,
decltype(t)::value_type
Requires C++11.
Reference: https://stackoverflow.com/a/13936644/577704
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