有以下一组对象和语句:
QSet<Foo*> set;
iterator QSet::insert(const T & value) //type of the function I want to call
const Foo * get() const //type of the function I use to get the argument
set.insert(get()); //the line showing up as error
我遇到了错误信息"no known conversion for argument 1 from 'const Foo*' to 'Foo* const&",由于我不太理解这些类型,所以我不知道该怎么做才能让它正常工作。
据我所知,const关键字应用于其左侧的类型,但顶层const可以写在其适用的类型左侧。我的猜测是我需要将get()转换为引用,但我不确定如何做到这一点。
const
”。get()
返回一个指向“const Foo
”的指针,而不是一个const
指针。 - Barryconst
开头的东西适用于其右侧的所有内容,这是错误的吗?那么这样的const
到底适用于什么呢? - Balz Guenat