I am trying to get familiar with the STL library, but I find it hard to understand my compilation error. I searched for other questions using the compiler error line βcould not derive the template argument for ...β, but none of the answers are applicable or relevant.
Error 4 of error C2784: 'bool std :: operator <(const std :: unique_ptr <_Ty, _Dx> &, const std :: unique_ptr <_Ty2, _Dx2> &)': the template argument for 'const std :: could not be output unique_ptr <_Ty, _Dx> & 'from' const std :: string 'c: \ program files (x86) \ microsoft visual studio 10.0 \ vc \ include \ xfunctional 125
I am writing a simple interpreter to calculate derivatives / integrals with respect to one variable. I want the card to match the internal management code entered by the user. The key is a trigger (or other) function, and int is the control code. I use a separate header file for #define functions, but for this example I just use integer literals. I am using Visual Studio:
#include <cstdio> #include <map> using namespace std; int main(int argc, char** argv) { map< string, int > functions; functions.insert( pair<string, int>("sin", 1) ); return 0; }
EDIT:
after Sergeβs attempt (which worked) to answer:
functions.insert(std::make_pair(std::string("sin"), 1));
I understood the error and tried this:
pair<string, int> temp = pair<string,int>("cos",2); functions.insert(temp);
although this is probably suboptimal, it illustrates the problem of not creating a paired object before inserting it into the map.