user721776
user721776

Reputation: 33

how to use map properly when passing through method inside class in c++

I can't make map work with a class, what's wrong here? I can't figure it out, please help:

#include <map>
#include <iterator>

class base {
public:

    bool delete_lowest(map<char, double> &frequencies)
    {
        double min=1; char del ; box b1;
        for (iterator itr = frequencies.begin(); itr != frequencies.end(); ++itr)
        {
            if(itr->second < min)
            {
                min= itr->second ;
                del= itr->first ;
            }
        }
        frequencies.erase(del) ;
        return true;
    }

I am getting errors like "map is not declared" and so on. I think the way I code is not the proper way. so how do I proceed? Thanks

Upvotes: 0

Views: 147

Answers (2)

Afiefh
Afiefh

Reputation: 1067

There are three solutions to your error:

  1. Instead of map use std::map
  2. add using std::map before your class
  3. add using namespace std before your class.

Upvotes: 2

dfan
dfan

Reputation: 5814

map is in the std namespace. Try

bool delete_lowest(std::map<char, double> &frequencies)

Upvotes: 5

Related Questions