编辑:这个问题应该被视为放弃。我已将此问题标记为删除,因为此时我什至不知道如何继续进行。我感谢你们所有人的意愿和抽出时间来帮助我。
我正在阅读并关注 cplusplus 关于数据结构的文档。我一直试图弄清楚为什么编译器不会接受“*pfruit.weight;”几个小时。可以肯定的是,我缺少一些简单的东西。
error C2228: left of '.weight' must have class/struct/union
1> type is 'product *'
1> did you intend to use '->' instead?
“句点 (.) 左侧的操作数不是类、结构或联合。”
那么我如何正确访问指针成员指向的值?(不访问引用)
#include <iostream>
using namespace std;
struct product
{
int weight;
float price;
} ;
int main ()
{
product afruit;
product * pfruit;
pfruit = &afruit;
pfruit->weight;
//Access a member of an object to which we have a reference
//equivalent to: (*pfruit).weight
*pfruit.weight; //<------ I am so sorry, i meant This is the problem, i am using a reworded line of code from an example and it isn't compiling and returning the error.
//Access the value pointed by a pointer member called weight;
//equivalent to: *(pfruit.weight)
system("pause");
return 0;
}