std::initializer_list<> and a Reference Parameter

Deadly 提交于 2019-12-05 17:22:52

When I try it, I get these errors. Yet, when I get rid of your pointless use of references, it all works.

std::initializer_list stores values, not references. You should be taking a const std::initializer_list<T> &, not a const std::initializer_list<T&> &.

All I'm trying to do is write a function that takes any number of arguments, by reference, and returns a reference to the largest of them. [...] Is this possible with initializer_lists?

No. std::initializer_list is for values, not references. But I see no reason why you couldn't take the items by value instead of by reference. Or, more to the point, why don't you just use std::min, which can take an initializer list?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!