Skip to main content
gamedev.net
🔒 Locked

header error

Started by Kalasjniekof 2 replies 350+ views
Original Post
Kalasjniekof
Kalasjniekof
hi, i've written a headerfile with common constants and functions most of my cpp files use. When I try to include it in more than 1 cpp file within my project I get the following error (I'm using devcpp): "multiple definition of 'myfunction(float)'" I think this can be prevented with precompiler directives, but I have no idea how to do this. Can it be done with #ifndef followed by a constant my header defines or are there better ways?
methinks
methinks
Have you put in an Inclussion guard?

At the very top of your header, before anything else, put the following:
#ifndef HEADERNAME_H
#define HEADERNAME_H

Obviously you replace HEADERNAME_H with the actuall name of your header.

At the very end of the file, add:

#endif

This makes sure that each header file is only declared once, no matter how many times it may be called.
Kalasjniekof
Kalasjniekof
still the same error. My header looks like this now. Is this right?
#ifndef MYMATH_H#define MYMATH_H#include <cmath>#define HALFPI 1.57079632679#define PI 3.14159265359#define TWOPI 6.28318530718#define DEGTORAD 0.01745329252 #define RADTODEG 57.2957795131float degtorad(float f_deg);float radtodeg(float f_rad);float degcosf(float f_angle);float degsinf(float f_angle);float degtanf(float f_angle);float adegcosf(float f_value);float adegsinf(float f_value);float adegtanf(float f_value);#endif

btw, the name of my header is mymath.h
can anyone help me with this?

[Edited by - Kalasjniekof on April 15, 2005 10:08:35 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.