Jump to content
  • Advertisement
Sign in to follow this  
Mizipzor

Global functions

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

At school weve been given a couple of tasks to do. There are some functionality all of these tasks all need, so instead of copying and pasting code all over the place I decided to put it into some global functions. I made a new file and called it Utilities.cpp and definde a couple of functions there like utInitOpenGL and utLoadTexture. Problem is, when I try to call these functions I get the error: error C3861: 'utLoadTexture': identifier not found They are apparently not defined. Do I, in some way, manually need to include a .cpp file? I thought that was just the headers. Ive actually never used global functions before, Im a hardcore OOPer, so Im unsure on how to go about this. The first reaction was to make a singleton class; CUtilities, but that felt like a bit of an overkill. How do I define the global function? Are there better ways to define the global functions?

Share this post


Link to post
Share on other sites
Advertisement

// function.cpp : definition

void frobnicate() {
// Body
};

// function.hpp : declaration

void frobnicate();

// user.cpp : usage

#include "frobnicate.hpp"
void use() {
frobnicate();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Mizipzor
Ah! Thanks, thats clearly one way to do it. Are there any particular reason why I should use .hpp instead of .h?


I use C as well as C++ files in my projects. In particular, the void frobnicate(); line line of code would be interpreted differently by the two languages, so I make sure to mention it's a C++ file. Besides, using .h for C++ files screws up my emacs syntax hilighting (since it expects C files).

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!