@TopToster

Не работает код?

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <exception>
#include <fstream>
#include <cstdint>
#include <tuple>
#include <utility>
using namespace std;
template <class First,class Second>
Second& GetRefStrict(map<First,Second>& m,const First f){
    if (m.count(f)==0) throw runtime_error("error");
    Second *res=&m[f];
    return res; //здесь подчеркивает
}
int main() {
    map<int, string> m = {{0, "value"}};
    string& item = GetRefStrict(m,0);
    item = "newvalue";
    cout << m[0] << endl; // выведет newvalue

    return 0;
}
  • Вопрос задан
  • 142 просмотра
Решения вопроса 1
@res2001
Developer, ex-admin
У вас GetRefStrict должна возвращать ссылку, а вы возвращаете указатель.
return *res;
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы