vendredi 4 décembre 2020

Dereferencing C++ pointer to type if possible

class Foo {
public:
    static const int BAR = 2;
};

typedef Foo T1;
typedef Foo* T2;

int value1 = T1::BAR;  // This works.
int value2 = T2::BAR;  // This doesn't work.

Can the value of BAR be extracted from T2?

I am using c++-11.

I imagine this would be bad practice but am curious if it can be done.

Aucun commentaire:

Enregistrer un commentaire