Intel C ++ error: "pair" is not a non-statistical data element or base class class "std :: pair <const int, double>"
I am using the Intel C ++ compiler with qmake in QtCreator. In my project, I am using std :: map.
std::map<int,double> dataBase; dataBase[2] = 2.445; This code compiles and runs without problems using g ++. If I try to compile with ICC, the following error will occur:
/usr/include/c++/4.8.0/tuple(1075): error: "pair" is not a nonstatic data member or base class of class "std::pair<const int, double>" The full compiler error is much longer. I got a little confused on the inclusion path, because for me it looks like the g ++ library that is used. If I comment on this section, the program compiles and I can verify that ICC has been used.
Does anyone know why the Intel C ++ compiler is causing this error?
Edit:
I create a minimal example and find a compiler option that causes this problem: Folowing is the contents of the * .pro file
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp QMAKE_CXXFLAGS += -std=c++11 main.cpp
#include <iostream> #include <map> using namespace std; int main(){ map<int,double> dataBase; dataBase[2] = 2.445; cout << dataBase[2] << endl; return 0; } He works without
-std=c++11 but causes a compiler error.
I have the same problem as you describe ... really strange. Every other compiler (clang, gcc, msvc11) compiles it without any problems. I think this is because of the 4.8.x headers. icpc -v says at least version 13.1.1 (gcc version **4.7.0** compatibility) ...
Workaround:
template<class K, class V> V &changemapvalue(std::map<K, V> &map, K &key, V &val) { #if defined(__GNUC__) && defined(__INTEL_COMPILER) if (map.find(key) != map.end()) map.erase(key); map.insert(std::pair<K, V>(key, val)); #else map[key] = val; #endif //__GNUC__ && __INTEL_COMPILER return val; } But this is stupid.
If you consider vector<char> , one element is represented as just a char .
A map however (and other associative containers) is not represented in this way. Rather, they are represented as a pair :
{C ++ 03} 23.3.1 / 2
typedef pair<const Key, T> value_type; I am not familiar with the Intel C ++ compiler, but judging by the error message, I would say that Intel implements pair in terms of the tuple class. A tuple class is a collection of things. A pair , for example, will be a tuple with two elements.
All of the above is just a study and does not really say why you get this error. /usr/include/c++/4.8.0 looks like the include directory for g ++ 4.8.0 - the latest version of g ++. If the Intel compiler is looking here, I would say that your paths are corrupted, both in your environment and in the paths sent to the Intel compiler.
Check the environment variables and your file.
When it comes to C ++ 11, for some reason icpc doesn't like the [] std :: map operator.
To enter new values you need to use the insert() method, and to access existing values you can use the C ++ 11 at() method.
This compiles with icpc -std=c++11
#include <iostream> #include <map> using namespace std; int main(){ map<int,double> dataBase; dataBase.insert(pair<int,double>(2,2.445)); cout << dataBase.at(2) << endl; return 0; }