# Global functions

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
// function.cpp : definitionvoid frobnicate() {  // Body};// function.hpp : declarationvoid frobnicate();// user.cpp : usage#include "frobnicate.hpp"void use() {  frobnicate();}

##### Share on other sites
Ah! Thanks, thats clearly one way to do it. Are there any particular reason why I should use .hpp instead of .h?

##### Share on other sites
Quote:
 Original post by MizipzorAh! 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 on other sites
I see. Thanks for the help, rating++ for you. :)

##### Share on other sites

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628721
• Total Posts
2984394

• 25
• 11
• 10
• 16
• 14