<分区>
我正在尝试使用 Visual Studio 2010 编译一些 C++ 代码,但出现以下错误:
error C2664: 'molder::Mold::set_piece_maker' : cannot convert parameter 1 from 'piece_maker::Piece_Maker *const ' to 'piecemaker::Piece_Maker *'
该错误指的是管理两个类之间相互引用的两个镜像函数:
void Piece_Maker::set_mold(molder::Mold* value, void* origin) {
if (this->mold == value)
return;
this->mold = value;
this->mold->set_piece_maker(this, this); // This is the line with the error
}
和:
void Mold::set_piece_maker(piecemaker::Piece_Maker* value, void* origin) {
if (this->piece_maker == value)
return;
this->piece_maker = value;
this->piece_maker->set_mold(this, this);
}
- 我没有在任何地方对这些类中的任何一个使用 const。
- 错误只发生在 mold->set_piece_maker() 行,而镜像的 piece_maker->set_mold() 行编译得很好。
- 编译器声称“this”是 const,但没有标记我对其 mold 属性的修改,也没有标记我传递的“this”作为 origin 参数。
- 当我实际将 set_mold() 设置为常量时,编译器会在尝试修改该函数中的模具并尝试将“this”作为原点传递时引发错误。
编译器引发该错误可能会发生什么?