I want to build a container for fractions. The key will represent the value of the fraction in double; The numerator and the denominator are stored in a pair.
std::map<double, pair<int, int>> m ();
I had problems with inserting and printing the elements. Can you tell me how to do it for this specific case?
I tried:
m.insert(make_pair(x/y, make_pair(x, y)));
gives me error
request for member ‘insert’ in ‘m’, which is of non-class type
‘std::map<double, std::pair<int, int> >()’ m.insert(make_pair(x/y, make_pair(x, y)));
for ( auto it1 = m.begin(); it1!=m.end(); ++it1) cout << it1->first << "->" << it1->second << endl;
gives
request for member ‘begin’ in ‘m’, which is of non-class type
‘std::map<double, std::pair<int, int> >()’ for ( auto it1 = m.begin(); it1!=m.end(); ++it1)
and many other ways shown on geeksforgeeks and SO that gave me the same error but i don't know why.