Hey yall, so we have an assignment dealing with maps, and I think I understand them, but I cannot get this one to work. I have a class (Apps) that contains a string for the name, a string for the type, and a float for the cost, and I want the name string to be the Key value for the map. I think I initialized the map correctly, but on line 2 I am getting the error "missing template arguments before '(' token". I understand that means I'm missing some a character somewhere, but in all the examples I'm seeing I have exactly what they have. I'd also like to insert already constructed objects, but I don't know if that is possible considering the emplace function. If anyone has any ideas or thoughts I'd really appreciate them!
For the syntactical issue, it's saying you need std::pair<TypeA, TypeB>(...) and not just std::pair(...). I think this can be automatically determined by the compiler in either C++17 or C++20, but don't quote me on that.
But notice your map is a mapping of string to 'Apps', but the first element of your pair is an int. If we change the map to <int, Apps>, then things work better.
Ganado, is right. You don't need to specify the template arguments to std::pair thanks to class template argument deduction (CTAD) that was introduced in C++17. The only problem with your code (using a modern compiler) is that you pass an int and not a string as the first argument when constructing the std::pair.
You can even leave out std::pair and just put the arguments inside { }. The compiler knows that the insert function expects a std::pair<std::string, Apps> and will automatically deduce that is what you want to construct.