视觉C++将其视为常量,而事实并非如此
visual C++ treating this as a const when it isn't
我正在尝试使用Visual Studio 2010编译一些C++代码,但收到以下错误:
错误 C2664: 'molder::Mold::set_piece_maker' : 无法将参数 1 从 'piece_maker::P iece_Maker *const ' 转换为 'piecemaker::P iece_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,但没有标记我对其mod属性的修改,也没有将我传递的"this"标记为源参数。
- 当我实际制作 set_mold() const 时,编译器会引发错误,以尝试修改该函数中的模具并尝试将"this"作为原点传递。
编译器引发该错误会发生什么?
问题不在于const
,这是一个顶级const
,无论如何都被忽略了。 看看垂直排列的两种类型:
piece_maker::Piece_Maker *const
piecemaker::Piece_Maker *
相关文章:
- 伪造事实↔false
- 为什么右值不能绑定到非常量左值引用,除了写入临时无效的事实?
- 如何在CLIPS中优化不同模板事实之间的模式匹配
- 无法在剪辑嵌入式应用程序中断言事实
- 生成(并非如此)出现特定字符串的随机字符串
- 链表显示;缺少..但事实并非如此
- C++ 通过引用传递单个元素数组 - 这是事实吗?
- C++ 矢量下标超出范围(但事实并非如此)
- 视觉C++将其视为常量,而事实并非如此
- C++前缀增量运算符返回左值这一事实的实际用法
- 此代码看起来像是删除了此对象,但事实并非如此
- C++ "warning: returning reference to temporary " - 但事实并非如此
- MSG类型背后的事实
- Json chuck事实解析
- 我的类主要是容器的前端,我应该公开这个事实吗
- 有什么方法可以解决 c++ 不支持运行时模板的事实吗?
- 利用vector的元素存储在堆中的事实
- 转化会失去限定符,但实际上并非如此
- 为什么is_constructible声称某物是可构造的,而实际上并非如此?
- 从 C/C++ 调用 Prolog 时将事实传达给 Prolog(不使用断言)