Domanda

I currently have this code snippet:

typedef std::pair<std::string,std::string> myPair;

std::multimap<int,pair > topNodes;

topNodes.insert(std::make_pair(someNode->counter,
std::make_pair(someNode->phrase,title)));

How do I create this multimap that has a key and two associated values? Or is there any better ways to do this?

error: no viable conversion from '__map_iterator<__tree_iterator<__value_type<[...], struct std::__1::pair, class std::__1::basic_string >>, class std::__1::__tree_node, class std::__1::basic_string > >, void *> *, [...]>>' to '__map_iterator<__tree_iterator<__value_type<[...], class std::__1::basic_string>, class std::__1::__tree_node >, void *> *, [...]>>'

I used How to insert a pair of std::pair inside another std::pair? as a reference for the insert.

È stato utile?

Soluzione

std::multimap<int,pair > topNodes; //Error cause > > not compiling

Why do you think it should? What's pair at this point?

Remember std::pair<> needs to have correct template parameters to instatiate it.

Or is there any better ways to do this?

You probably meant something like this:

typedef std::pair<std::string,std::string> myPair;

std::multimap<int,myPair> topNodes;
// ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top