this is my code:
and this is my error:Code:void Cat::Eat()
{
printf("\n%s ate.", name);
}
// ... other functions with same error
"Local Function Definitions are illegal."
What does that mean?
I'm using MSVC++7.
Printable View
this is my code:
and this is my error:Code:void Cat::Eat()
{
printf("\n%s ate.", name);
}
// ... other functions with same error
"Local Function Definitions are illegal."
What does that mean?
I'm using MSVC++7.
Make sure you didn't leave out a closing brace. Otherwise, post some more code, please.
I fixed THAT problem. I have another one, however. It happens somewhere in here:
the program crashes when I input the age. The age is an int.Code:int main()
{
// get name & set
printf("What is the cat's name? ");
scanf("%s",cat.name);
// get age & set
printf("\nWhat is the cat's age? ");
scanf("%i",cat.age);
// get weight & set
printf("\nWhat is the cat's weight? ");
scanf("&i",cat.weight);
//printf("\nNAME: %s",cat.GetName());
printf("\nAGE : %i",cat.age);
return 0;
}
Why are you using scanf/printf with C++? You should be using cin/cout.
try using %d instead of %i
I solved the input problem using "cin".
However, although I like C++ input (cin), I like C output (printf,etc.). It doesn't really matter, does it?
printf() is slightly faster, anyways.
what XSquared said.
But as for y it's crashing, i'd say because u need to pass cat.age's address.
scanf takes the address of an object, so
it doesn't crash on cat.name (assuming name is a string) because when using an identifier for an array it passes the address of the first element.Code:scanf("%i",&(cat.age));
That's right, Kyro! Darn! I always forget that scanf takes the adress. Silly me.