[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bad syntax error on nested classes' member functions.



This is not a bug in the compiler, but in your code. Looking at the
declaration

  foo_t a::b::frobnicate() {

I notice that the scope of a::b is only reentered at the opening ( of
the method declaration, thus "foo_t" is *not* found to be the
typedef. Instead, it is treated as a plain identifier (of a function
or object). OTOH, "a" is a typename. So "foo_t a" is the sequence

  <identifier> <typename>

There is no declaration in C++ that starts with that sequence, hence
the token before the first "::", i.e. the "a", gives a syntax error.
To correct this error, you need to write

  a::b::foo_t a::b::frobnicate() {

as you found out. In case you wonder why foo_t alone is not yet a
syntax error: GCC still supports

  foo_t(){

for backwards compatibility (ie. as a function with an implicit int
return type).

Regards,
Martin



Reply to: