0

I have the following code:

    std::string s("abcdef");
    std::string::iterator first = s.begin();

    char c1 = *first; // this works

    std::make_pair<char, int>(*first, 1); // this doesn't work 

So when I dereference the string iterator to a standard char, it works fine. However when I use it directly in a std::make_pair call, it doesn't seem to work. What is the reason for this?

Thank you.

simplename
  • 717
  • 7
  • 15
  • Works for me anyway http://codepad.org/oKf2HMhr – Rushikesh Deshpande Feb 23 '17 at 07:42
  • *doesn't seem to work* is not a useful description, you should post the error you're seeing. I'm guessing the linked duplicate answers your question. To add to the answer to that question, the whole reason for `std::make_pair`'s existence is to deduce template arguments. If you want specify template arguments explicitly, then write `std::pair(*first, 1)`, it'll compile and it's fewer characters to type. – Praetorian Feb 23 '17 at 07:42
  • 2
    @RushikeshDeshpande Doesn't compile if you're using a C++11 compiler - http://coliru.stacked-crooked.com/a/dcda55d875f77b7c – Praetorian Feb 23 '17 at 07:44

0 Answers0