Possible Duplicate:
C++0x decltype and the scope resolution operator
Compiling next example using g++ 4.6.1:
#include <iostream>
struct A
{
static const int v = 1;
};
int main()
{
A a;
std::cout << decltype(a)::v << std::endl;
}
will produce next compiling errors:
error: expected primary-expression before 'decltype'
error: expected ';' before 'decltype'
Is this according to the standard? Or, is it a g++’s quirk?
It looks as if the compiler isn’t recognizing the
decltypekeyword.G++ 4.6.1 is new enough to include the
decltypekeyword. Did you enable C++11 mode with-std=gnu++0xor-std=c++0x?The C++ grammar does permit a decltype-specifier to appear before
::in a qualified-id, so the code will be accepted by a conforming compiler. The error message is wrong,decltype(a)::vis a valid qualified-id, which is a primary-expression.As a workaround, you can use a typedef. Example: http://ideone.com/clone/7FKUJ