Jump to content
  • Advertisement
Sign in to follow this  
redwingdw

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

This topic is 4476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!