I'm trying to familiarize myself with the STL library, but I'm having trouble understanding my compilation error. I've searched for other questions using the compiler error string "could not deduce template argument for..." but none of the answers appear applicable or relevant.
Error 4 error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional 125
I'm writing a simple interpreter for calculating derivatives/integrals in one variable. I want a map for matching the user's input to an internal control code. The key is a trig (or other) function, and the int is the control code. I'm using a separate header file to #define the functions, but for this example i'm just using integer literals. I'm 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 trying Serge's (which worked) answer:
functions.insert(std::make_pair(std::string("sin"), 1));
i realized the mistake and tried this:
pair<string, int> temp = pair<string,int>("cos",2);
functions.insert(temp);
though this is probably suboptimal, it illustrates the issue of not having constructed the pair object before inserting into the map.
Make sure that you have string header included.
#include <map>
#include <utility>
#include <string>
...
std::map<std::string, int> functions;
functions.insert(std::make_pair(std::string("sin"), 1));
<string>
char** argv[]
has to be const char* argv[]
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