"Expected unqualified-id before 'namespace'" error
From where is this file included. There's nothing wrong with the file
you posted; what I suspect is happening is that the file which includes
it has already includes <string>
(so this include does nothing), and
is missing a ;
immediately before it includes your file.
One way to track down such errors is to start from the ground up:
#include "filepath/ui.h"
int main () { return 0; }
Does this compile? (This works fine with the little snippet of ui.h that you supplied.)
Errors like these are often caused by a missing semicolon on some previous class declaration. So let's try to force the issue:
struct Foo { int foo; } // Note the missing semicolon after the close brace.
#include "filepath/ui.h"
int main () { return 0; }
This of course does not compile clean. I get a convoluted include path trace from my testmain.cpp to your filepath/ui.h to string ... and eventually get
/usr/include/i386/_types.h:37: error: two or more data types in declaration of '__int8_t'
So that isn't the error, but the missing semicolon sure is creating a mess. Your error isn't arising deep in the bowels of <string>
, so let's make our test program #include <string>
before trying to recreate the error:
#include <string>
struct Foo { int foo; } // Note the missing semicolon after the close brace.
#include "filepath/ui.h"
int main () { return 0; }
And the error message is
In file included from testmain.cpp:5:
filepath/ui.h:6: error: expected unqualified-id before 'namespace'
And there it is. So some other header that you #include prior to filepath/ui.h has a badly-formed class declaration.
Addendum
Sometimes it helps to use a different compiler. g++ is notorious for its bad treatment of this common programming error. Compiling the above with clang yields
testmain.cpp:4:2: error: expected ';' after struct
So, tada, clang has zeroed in on the problem.
What is happening is that when a compiler runs into trouble it applies some fix to your code to make it grammatically correct. The compiler error message is based on this autocorrection. Note well: This autocorrection is in general a very good thing. Without it the compiler would necessarily have to shut down at the first error. Since programmers inevitably make more than one error, hunting them down one at a time would be a pain in the rear.
I haven't the foggiest idea what goofy correction g++ applies to fix the missing semicolon problem, other than it is not to add the obvious missing semicolon. clang adds the missing semicolon, and that is what it complains about.