I was writing a program for a class using Visual C++ on my home computer, however, I tried to run it on school linux computers and I get these errors.
std::tr1::unordered_map <string, Word*> map;
Both of these errors appear on the line of code above
ISO C++ forbids declaration of ‘unordered_map’ with no type
expected ‘;’ before ‘<’ token
Originally I used hash_map but found out that could only be used in Visual C++
Thanks
GCC and MSVC define the TR1 extensions in different ways, because the TR1 standard is vague about how it should be supplied to the user. It simply specifies that there should be some compiler option to activate TR1.
Unlike MSVC, GCC puts the headers in a TR1 subdirectory. There are two ways to access them:
-isystem /usr/include/c++/<GCC version>/tr1. This is more conformant but appears to cause problems.Use conditional compilation:
#ifdef __GNUC__
#include <tr1/unordered_map>
#else
#include <unordered_map>
#endif
This exposes GCC's nonconformance: TR1 is not activated by setting an option, but instead by modifying the code.
There is a somewhat esoteric way around this: computed header names.
#ifdef __GNUC__
#define TR1_HEADER(x) <tr1/x>
#else
#define TR1_HEADER(x) <x>
#endif
#include TR1_HEADER(unordered_map)
This way, you only have to include things "once."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With