On Oct 27, 8:12 pm, Joshua Maurice<joshuamaur...@gmail.com> wrote:
On Oct 27, 3:49 pm, Jonathan Lee<jonathan.lee....@gmail.com> wrote:
So I think I've seen somewhere that you can access a class-scoped
typedef via the dot operator, like other members. For example,
std::vector<double> v;
/* do something with v.value_type */
The thing is, I can't seem to actually do anything with it. Can't take
the size of it, can't construct a variable, etc. But the compiler
errors suggest it's actually figuring out that I *mean*
std::vector<double>::value_type. What can you actually accomplish with
this notation? Or is it even valid?
value_type is a type name, not a data member or function member. The
dot operator is used to access data members and function members. The
scope resolution operator "::" is used for things like nested type
names. The compiler is telling you exactly that. The syntax to use
value_type is "std::vector<double>::value_type". Ex:
#include<vector>
std::vector<double>::value_type some_variable;
What exactly is your question?
Sorry, I misremembered the example. I thought it was for typedefs,
but it was actually for enums. i.e,
class A {
public:
enum dir { left, right };
};
int main() {
A a;
A* b =&a;
std::cout<< static_cast<int>(a.left)<< std::endl;
std::cout<< static_cast<int>(b->left)<< std::endl;
}