[英]C++ passing a structure to a function
I am trying to pass a structure to my function but I can't figure it out. 我正在尝试将结构传递给函数,但无法弄清楚。 I have the code below 我有下面的代码
struct box
{
char sMaker[40];
float fHeight; //The height of the box
float fWidth; //The width of the box
float fLength; //The length of the box
float fVolume; //The volume of the box
}; //end box
void calcVolume (box *p)
{
p‐>fVolume = p‐>fWidth * p‐>fHeight * p->fLength;
} //end calcVolume
It returns the error that p‐ is an undeclared identifier. 它返回错误p是一个未声明的标识符。 I'm really new to c++ why's it not compiling. 我真的是C ++新手,为什么不编译。
Thank you so much. 非常感谢。
Looking at one of your dashes ( -
) using emacs
's describe-char
: 使用emacs
的describe-char
查看破折号( -
)之一:
preferred charset: unicode (Unicode (ISO10646))
code point in charset: 0x2010
name: HYPHEN
general-category: Pd (Punctuation, Dash)
Replace them all with a minus sign. 将它们全部替换为减号。
Check that your source file is plain ASCII. 检查您的源文件是否为纯ASCII。 It seems to me that you are using some extended unicode character in place of the "minus" sign '-' 在我看来,您正在使用一些扩展的unicode字符来代替“减号”-
The error is probably in the code that calls calcVolume (or somewhere else entirely). 错误可能出在调用calcVolume的代码中(或完全在其他位置)。 You need to call it like this: 您需要这样称呼它:
box b;
calcVolume(&b);
Edit: Nevermind, the real error is the hyphen (‐) instead of the minus sign (-). 编辑:没关系,真正的错误是连字符(-)而不是减号(-)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.