map<string, int> Employees; 

Employees.insert(map<string,int>::value_type("John A.",7582));

what does the value_type do?

what is the difference between pair() and make_pair()

map<string, int> Employees;

Employees.insert(map<string,int>::value_type("John A.",7582));

what does the value_type do?

what is the difference between pair() and make_pair()

The std::map<Key, Value>::value_type is just a typedef to std::pair<Key, Value>. So, there is no difference between them.

And the make_pair() is defined like the form:

template <typename T, typename U>
std::pair<T, U> make_pair(const T& first, const T& second) {
    return std::pair<T, U>(first, second);
}

When you need a pair, the make_pair() function can be shorter than pair class, and less error-prone:

empolyees.insert(pair<string,int>("John A.", 7582));
empolyees.insert(make_pair("John A.", 7582));

Edited 4 Years Ago by Reverend Jim: Fixed formatting

The std::map<Key, Value>::value_type is just a typedef to std::pair<Key, Value>. So, there is no difference between them.

And the make_pair() is defined like the form:

template <typename T, typename U>
std::pair<T, U> make_pair(const T& first, const T& second) {
    return std::pair<T, U>(first, second);
}

When you need a pair, the make_pair() function can be shorter than pair class, and less error-prone:

empolyees.insert(pair<string,int>("John A.", 7582));
empolyees.insert(make_pair("John A.", 7582));

end quote.

Very good. I gave you an up vote.

Edited 4 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.