Global functions

Started by
3 comments, last by Mizipzor 17 years, 4 months ago
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?
Advertisement
// function.cpp : definitionvoid frobnicate() {  // Body};// function.hpp : declarationvoid frobnicate();// user.cpp : usage#include "frobnicate.hpp"void use() {  frobnicate();}
Ah! Thanks, thats clearly one way to do it. Are there any particular reason why I should use .hpp instead of .h?
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).
I see. Thanks for the help, rating++ for you. :)

This topic is closed to new replies.

Advertisement