struct Foo
{
typedef int Bar;
};
int main()
{
Foo f;
decltype(f)::Bar x = 5;
return 0;
}
C++ decltype troubles
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.
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:
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
Popular Topics
Advertisement