error: there are no arguments to 'at' that depend on a template parameter, so a declaration of at must be available

微笑、不失礼 提交于 2019-12-04 06:55:51

Replace at with vector<T>::at or this->at.

Rules for how functions are looked up in templates are tighter now than when C++ was being originally designed.

Now, methods in dependent bases are only looked up if you this->, otherwise it is assumed to be a global function (or a non-dependent base/class local/etc).

This can help avoid nasty surprises in practice, where what you thought was a method call becomes a global one, or a global call becomes a method call. It also allows earlier checking of template method bodies.

In addition to Yakk's answer, another solution would be to add

using vector<T>::at;

to Vec basically adding it to the list of looked up functions.

This way, at() can be used as usual without prefixing it with the base class type or this->.

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