how to I pass a Paddle object to the Draw Class method

Started by
2 comments, last by redwingdw 17 years, 8 months ago
Hi I am trying to pass a Paddle object e.g Paddle player_paddle to a draw method


so heres the draw class

class Draw {
setPlayerP_movement(Paddle aPaddle);
};

Draw::setPlayerP_movement(Paddle aPaddle){

}




but I am getting an error that Paddle is undeclared identifier .....Paddle is definately a class
Advertisement
The order in which you declare classes/variables in languages such as C and C++ is important. If Paddle is declared after Draw then you'll get an undeclared identifier error as the compiler has not yet reached the Paddle class.

What you might want to do to solve this is create two header files, one for Draw and one for Paddle. Have thme both include eachother(Draw.h includes Paddle.h, Paddle.h includes Draw.h), but be sure to use what are called "include guards" so the compiler does not include the same file twice(this will cause even more errors).

Also the "proper" way to pass aPaddle is as a pointer of reference, not a copy.

setPlayerP_movement(Paddle *aPaddle);

or

setPlayerP_movement(Paddle &aPaddle);
Assuming C++...

The Paddle class has to be defined in the file that is being compiled, and before it is used. You could define it directly in the file, but it is usually better to define it in a header file and then include the header file.

If you are already doing that, then you need to show more relevant code.

John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks folks it was eactly as you said .......I am not using header files its all in one file and I changed the order and it fixed the problem.

I think I will try and change my program so its using header files ......I better do some reading up on include gaurds )

I have been programming for a long time today and I am starting to get dumb errors from not doing basic stuff like initialising certain constructor variables so Im going to give it a break for tonight :-)

Thanks for the help!
Dave

This topic is closed to new replies.

Advertisement