2013-02-13 124 views
0

我想将结构传递给我的函数,但我无法弄清楚。我的代码如下C++将结构传递给函数

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 

它返回p-是一个未声明的标识符的错误。我真的很陌生,为什么它不编译。

非常感谢。

+1

该代码是正确的AFAICT,虽然你可能想要一个引用,双打和一个'std :: string'。 – chris 2013-02-13 22:54:14

+3

如果这应该是C++ OOP,那么我也会让它成为一个具有返回音量的成员函数的类。我也摆脱了匈牙利的符号。布莱什。 – 2013-02-13 22:55:09

回答

4

看你的破折号之一(-)“”:

preferred charset: unicode (Unicode (ISO10646)) 
code point in charset: 0x2010 
name: HYPHEN 
general-category: Pd (Punctuation, Dash) 

更换他们都有一个负号。

+0

+1有关详细说明。我只想添加gcc的输出:http://ideone.com/vVa6Nw – LihO 2013-02-13 23:09:46

+0

由于某种原因,当我输入高于我所拥有的完全相同的计算值时,它的工作原理。我猜它在visual studio中有一些bug。 – user2070244 2013-02-14 00:06:44

1

该错误可能是在调用calcVolume(或其他地方完全)的代码中。你需要这样称呼它:

box b; 
calcVolume(&b); 

编辑:没关系,真正的错误是连字符( - )而不是减号( - )。

2

检查您的源文件是纯ASCII。在我看来,您正在使用到位“减”号的一些扩展的Unicode字符 - 使用emacsdescribe-char