【发布时间】:2021-07-29 08:40:24
【问题描述】:
我正在为一个类构建一个方法,如下图
const int PointArray::getSize() const
{
int c=0;
while(s[c])
{
c++;
}
const con=c;
return con;
}
而类的头文件是这样的
class PointArray
{
point *s;
int len;
public:
PointArray();
virtual ~PointArray();
const int getSize() const;
};
class point
{
private:
int x,y;
public:
point(int i=0,int j=0){x=i,y=j;};
};
然后它引发错误:无法转换 '*(((point *)((const PointArray *)this)->PointArray::s) + ((sizetype)(((long long unsigned int)c) * 8)))' 从“点”到“布尔”
我不知道如何调试。
【问题讨论】:
-
getSize()只需要返回len。 -
minimal reproducible example 中的哪一行会触发此错误? (我看不到任何接近它的东西——特别是,我在您的代码中看不到
* 8。)您为什么期望point对象可以转换为bool? (通常,通过添加您认为编译器错误的原因来引发错误,可以改进此类问题。) -
s[c]的类型为point。point是真还是假意味着什么?你希望while(s[c])在什么情况下运行循环体,或者退出循环?
标签: c++ class pointers methods types