Jump to content
  • Advertisement
Sign in to follow this  
nibbuler

C++::Call a function from another source file?

This topic is 3789 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

From Main.cpp Free Image Hosting at www.ImageShack.us (Click to enlarge) Here's some of Player.h Image Hosted by ImageShack.us I declared class Player in Player.h, defined it in Player.cpp, but I can't call it in Main.cpp... [Everything is in stdafx.h, and both source files #include it] I need to do this in the main loop... Not sure how to call it altogether because even when I put everything from Player.cpp into Main.cpp, and use Player::handle_input(); it says that it's illegal. What's the syntax to do such a thing? (Preferably to call it from Player.cpp in the Main.cpp loop) Help is much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The smaller image displays that you are treating Player as an object, but you said you have declared it as a class.

Do you declare an object for type Player? If not, then this is the problem. A class describes an object, it does not create it. Because of this, Player.some_method() is incorrect.

Share this post


Link to post
Share on other sites
Quote:
Original post by nibbuler
Awesome, mate. That's all it took... adding
Player Player;
to main().

Thanks a ton!

I would not recommend naming an instance the same as it's class. That's going to add confusion, if it's even allowed to do so. At least go for lowercase for the instance names, or give them a different (but descriptive) name altogether.
Player player;
or
Player bob;
would be better.

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!