我想用一个成员函数来调用当前对象本身,但是报错:
error: reference to type 'const block' could not bind to an rvalue of type 'block *'
if (otherBlks[mm].theNeighbourPolyline(this) == 1)
^~~~
~/blockI.hpp:358:59: note: passing argument to parameter 'blockX' here
inline const int block::theNeighbourPolyline(const block& blockX) const
错误发生在我试图添加一个新的成员函数void block::bdsmooth(const vector<block>& otherBlks)
.在这个成员函数中,theNeighbourPolyline(otherBlks[mm])
工作正常,但是 otherBlks[mm].theNeighbourPolyline(this)
好像是不允许的。
我应该怎么做才能克服这个问题?
最佳答案
this
是一个指针值,但您的函数正在寻找一个引用参数。尝试:
if (otherBlks[mm].theNeighbourPolyline(*this) == 1)
关于c++ - 这里不允许`*this`,求解决办法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22420860/