user2070244
user2070244

Reputation: 3

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. I'm really new to c++ why's it not compiling.

Thank you so much.

Upvotes: 0

Views: 83

Answers (3)

user1610015
user1610015

Reputation: 6668

The error is probably in the code that calls calcVolume (or somewhere else entirely). You need to call it like this:

box b;
calcVolume(&b);

Edit: Nevermind, the real error is the hyphen (‐) instead of the minus sign (-).

Upvotes: 1

Anton Kovalenko
Anton Kovalenko

Reputation: 21507

Looking at one of your dashes (-) using emacs's 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.

Upvotes: 4

Emanuele Paolini
Emanuele Paolini

Reputation: 10162

Check that your source file is plain ASCII. It seems to me that you are using some extended unicode character in place of the "minus" sign '-'

Upvotes: 2

Related Questions