Std :: map.insert "Could not print the template argument for ..."

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.

+4
source share
2 answers

Make sure the title bar is included.

 #include <map> #include <utility> #include <string> ... std::map<std::string, int> functions; functions.insert(std::make_pair(std::string("sin"), 1)); 
+7
source
  • You did not include <string>
  • char** argv[] must be const char* argv[]
+3
source

Source: https://habr.com/ru/post/1393652/


All Articles