Jump to content
  • Advertisement
Sign in to follow this  
siliconsurfer

Calling methods

This topic is 4827 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
Advertisement
Why not just create it as a normal method then?

void foo()
{
// Your code here
}



Unless you're using Java. What language are you using?

Share this post


Link to post
Share on other sites
I'd have to suggest a namespace for static non-member functions:
namespace misc {
void foo() {
// code
}
}

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!