Sign in to follow this  
Mizipzor

Global functions

Recommended Posts

Mizipzor    247
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
ToohrVyk    1595

// 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
ToohrVyk    1595
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

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