无法将'DATA_UNIT::getc1'从类型 'char (DATA_UNIT::)()' 转换为类型 'char'

cannot convert 'DATA_UNIT::getc1' from type 'char (DATA_UNIT::)()' to type 'char'

本文关键字:类型 char UNIT DATA 转换 getc1      更新时间:2023-10-16
char getc1(){return this->c1;}

我得到了这种方法作为获取

DATA_UNIT::DATA_UNIT(const DATA_UNIT& Clone)
{
this->c1=Clone.getc1;
this->c2=Clone.getc2;
this->c3=Clone.getc3;
}

使用它后,我收到此错误:

cannot convert 'DATA_UNIT::getc1' from type 'char (DATA_UNIT::)()' to type 'char'

使用您的源代码,很明显 getcN 是方法,因此您必须调用它们才能获取字符,这正是错误告诉您的:"无法将接受参数的东西转换为 char"。

此外,正如评论中已经指出的那样,使用 this->c1 访问成员是没有用的。只需 c1 即可。