Expected `)' before ‘aFoo’

From Cppsyntax

Jump to: navigation, search

You can (presumably) get the error message

expected `)' before ‘tile’

several ways.

Class not defined

WRONG

blort.h:

 class Blort {
   Blort(Foo);
 };

blort.cc:

 #include "blort.h"
 Blort::Blort(Foo aFoo) {   // Foo not defined
   // stuff
 }

RIGHT

foo.h:

 class Foo {
   // stuff
 }

blort.h:

 #include "foo.h"   // now Foo is defined
 Class Blort {
   Blort(Foo);
 };

blort.cc:

 #include "blort.h"
 Blort::Blort(Foo aFoo) {
   // stuff
 }

Why does it do this? Why doesn't it complain with

 ‘Foo’ was not declared in this scope ?

Because there is some ambiguity with parentheses: sometimes they denote expressions (e.g. "(2+3)/4"), sometimes they denote argument lists (e.g. "wacka(2,"a ball", 27)"), or casts (e.g. "int i = (int) 2.0/3.0;"). In this case, the parser could decide exactly what the "(" was part of, so bailed and gave a more general error message. Sorry.

Personal tools