我知道这个(*x).y就像c++中的x->y,但这段代码是为我编写的。有没有人可以帮我或者给我一个推荐信?
发布于 2012-09-14 07:09:44
总的来说,使用变量名中的术语,它将currentHtml()函数的返回值存储到manifest的currentItem的fileContent变量中。
要分解它,请执行以下操作:
((ManifestItem*)manifest->currentItem())在您的manifest类中有一个方法currentItem(),它将返回"current item“。(ManifestItem*)会将此返回项转换为ManifestItem数据类型。
剩下的,我希望是不言而喻的:
->fileContent = currentHtml();发布于 2012-09-14 07:12:43
((ManifestItem*)manifest->currentItem())->fileContent = currentHtml();1)调用currentHtml()
2)将清单转换为指向ManifestItem的指针
3)取消引用#2中的指针,并调用其currentItem成员函数
4)取消引用#3,并将#1中的值分配给它的fileContent数据成员--或者使用operator=()
发布于 2012-09-14 08:01:29
((ManifestItem*)manifest->currentItem())->fileContent = currentHtml();在cpp中是什么意思?
这意味着有人在做坏事。
首先,你把你的问题放在标题里是在做坏事。其次,这种转换是可疑的迹象。但是..。
您需要知道的第一件事是C++运算符优先规则。元素选择运算符->优先于强制转换运算符(type),因此这意味着我们可以将其重写为
((ManifestItem*)(manifest->currentItem()))->fileContent = currentHtml();把它分成几部分,
manifest对象的currentItem()成员函数,该函数可能返回某种类型的指针。考虑到强制转换,我怀疑currentItem()返回一个void*指针。ManifestItem对象的指针。fileContent成员被设置为调用cast的结果https://stackoverflow.com/questions/12416028
复制相似问题