Я понимаю, что это вызвано const type self.at(idx)
, но не знаю, как исправить это в таком статическом методе.Как вернуть тип const в статическом методе?
template<class Key, class Val>
struct map_item
{
typedef std::map<Key,Val> Map;
static Val& get(Map const& self, const Key idx) { return self.at(idx); }
} // is it legal to be static? but I need 'static'
Ошибка:
error: invalid initialization of reference of type ‘std::basic_string<char>&’ from expression of type ‘const mapped_type {aka const std::basic_string<char>}’
static Val& get(Map const& self, const Key idx) { return self.at(idx); }
Ваш вопрос не имеет смысла. Что вы на самом деле пытаетесь сделать? –
Вы должны отправить строку, откуда исходит ошибка. – texasbruce
@texasbruce: Он сделал. –