在C++应用struct 指向member时是使用“.“还是"->",总另人感到困惑,C++ 书中是这么写的:
1. 若struct的名字不是指针时,用".";
2. 若struct的名字是指针时,用"->";
如下:
另外,结构体里面尽量不要使用string类定义,例如
struct inflatable
// struct template
{
std::string name;
float volume;
double price;
};
在语法上是允许的,但是不建议。因为这样做就不知道struct 的大小,不能用new分配内存空间。