Sign in to follow this  

Calling methods

This topic is 4664 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'm writing a game, and I'm using a oo design, however there are some functions which don't really belong to an object. I'd like to be able to call them the same way you can call functions like printf(); Can anyone explain to me how to do this, without creating an object?? Thanks

Share this post


Link to post
Share on other sites
You can extern the declaration in a header.


//in Global.h

namespace system
{
extern void print(std::string message);
}





and then implement it anywhere else


//in Global.cpp
void print(string message)
{
cout<<message;
}






Just #include "Global.h" anywhere you want to call system::print("Hello World")l

Share this post


Link to post
Share on other sites

This topic is 4664 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.

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