"error: expected unqualified-id before numeric constant"
-
Ich hab folgenden (C++)-Code, der unter Windows problemlos kompliliert wird, aber bei Linux bekomme ich folgenden Fehler:
In file included from ./src/Useful.cpp:8:
./src/Useful.h:18: error: expected unqualified-id before numeric constant
./src/Useful.cpp:14: error: expected unqualified-id before numeric constant
./src/Useful.cpp: In function âstd::string useful::time2str(long long int)â:
./src/Useful.cpp:24: error: expected unqualified-id before numeric constant
./src/Useful.cpp:24: error: expected â)â before numeric constant
./src/Useful.cpp:38: error: âsnprintfâ was not declared in this scopeuseful.h:
#ifndef USEFUL_H_ #define USEFUL_H_ #include <string> void printTime(const char* prefix, long long &t0, long long &t1); std::string time2str(long long time); namespace useful { extern bool debug; extern bool linux; // line 18 void printTime(const char* prefix, long long &t0, long long &t1); std::string time2str(long long time); } #endif /* USEFUL_H_ */
useful.cpp:
#include "Useful.h" // line 8 #include <string> #include <iostream> using namespace std; bool useful::linux = true; bool useful::debug = true; void useful::printTime(const char* prefix, long long &t0, long long &t1) { t1 = clock(); cout << prefix << time2str(t1 - t0) << endl; t0 = t1; } string useful::time2str(long long time) { if (useful::linux) time /= 1000; // line 24 int ms = time % 1000; time /= 1000; int sec = time % 60; time /= 60; int min = time % 60; time /= 60; int h = time % 24; time /= 24; int d = time; const int size = 255; char buffer[size]; snprintf (buffer, (size_t) size, "%dd %dh %dmin %ds %dms", d, h, min, sec, ms); // line 38 string s = string(buffer); return s; }
Ich vermute stark, dass es etwas mit dem extern zu tun hat. Was gibt es für Alternativen für globale Variablen, falls der Compiler unter Linux extern nicht unterschützt?
-
Die Art des Fehlers lässt vermuten, dass da ein Makro linux im Weg ist, evtl als Teil das Compileraufrufs definiert?
-
Danke, mit linux1 klappt alles problemlos.