C++ decltype troubles

Started by
0 comments, last by Sneftel 12 years, 10 months ago
How can I use decltype to access stuff declared in a class? Sorry, I don't know the technical terms for what I'm trying to do, but here's an example. No matter what I try, I can't get it to work.

struct Foo
{
typedef int Bar;
};

int main()
{
Foo f;
decltype(f)::Bar x = 5;
return 0;
}
I trust exceptions about as far as I can throw them.
Advertisement
As currently implemented in compilers, that code is wrong; a modification to the standard which would allow it happened just a couple of months ago, though.

Workaround:



template<typename T>
struct BarGetter
{
typedef typename T::Bar BarType;
};


int main()
{
Foo f;
BarGetter<decltype(f)>::BarType x = 5;
}

This topic is closed to new replies.

Advertisement