I am new to c++ (and c for that mater) and I was trying to compile the
attached files using g++ Dinosaur.cc. the problem occurred when I tried to return a struct from a function that.
The function is declared in the Dinosaur.hh as follows
int setLengthOfSleep(int iHours,int iMinutes);
and the function I tried to call in Dinosaur.cc was:
struct Dinosaur::getLengthOfSleep()
{
return mhamLengthOfSleep;
}
(note: I originally tried the funtion as follows:
hoursAndMinutes Dinosaur::getLengthOfSleep()
{
return mhamLengthOfSleep;
}
to which the compiler said:
Dinosaur.cc:121: parse error before `::'
Dinosaur.cc: In method `int Dinosaur::getLengthOfSleep()':
Dinosaur.cc:122: new declaration `int Dinosaur::getLengthOfSleep()'
Dinosaur.hh:48: ambiguates old declaration `struct
Dinosaur::hoursAndMinutes Dinosaur::getLengthOfSleep()'
Dinosaur.cc: In method `int Dinosaur::getLengthOfSleep()':
Dinosaur.cc:123: `struct Dinosaur::hoursAndMinutes' used where a `int'
was
expected
but I expect that this is because I did something wrong)
-Jonathan Harris