Inside your Draw
function there is no variable declared called mysnake
. That function can't see the mysnake
that's declared in main
because it is local to main
. You need to pass your mysnake
object to the Draw
function so that it knows which snake you're actually talking about.
To do that, give Draw
an argument of type const Snake&
, a "reference to const Snake
" (or take away the const
if EndSnake
is a non-const
member function):
bool Prog::Draw(const Snake& snake) {
// ...
}
And when you call Draw
in main
, do this:
run.draw(mysnake);
Now your Draw
function has a variable called snake
which was passed in from main
. Because the argument is a reference, the Snake
object that it sees is exactly the same object as in main
. If the argument had been of type Snake
instead of const Snake&
, then you would get a copy of the mysnake
from main
.
Some extra advice:
We usually write conditions like (run.Init())==false
as just !run.init()
- it reads much better. Returning is also usually written as return true;
, rather than return(true);
, but that's up to you.