class Foo {
public:
static const char *constant_string;
};
auto Foo::constant_string = "foo";
int main(void) {
};
Compiled with: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 like this:
gcc -std=c++0x ./foo.cc
./foo.cc:6:11: error: conflicting declaration ‘auto Foo::constant_string’
./foo.cc:3:22: error: ‘Foo::constant_string’ has a previous declaration as ‘const char* Foo::constant_string’
./foo.cc:6:11: error: declaration of ‘const char* Foo::constant_string’ outside of class is not definition [-fpermissive]
Is this intended behavior of the auto
keyword, or a bug in gcc+
Visual C++ accepts
It's disallowed by the language:
It's hard to prove a negative, but there's simply no explicit rule in the standard to allow
auto
in your case.However, the same rules mean that the following is valid:
(Note that the type of
Foo::constant_string
ischar const* const
rather than, say,char const[3]
; this is an effect of usingauto
.)