Sign in to follow this  
nibbuler

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this