# files

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

## Recommended Posts

Hi, I'm working eith Dev and I have this strange problem, for the header file I have:
#ifndef MATHDEF_H
#define MATHDEF_H

float Distance(float point1x , float point1y , float point2x , float point2y);
int AbsDistance(int point1x , int point1y , int point2x , int point2y);
int Normal(int point);

#endif


and for the file I have:
#include <iostream.h>		// Header File For Windows
#include <stdio.h>			// Header File For Standard Input/Output
#include <math.h>

#include "Mathdef.h"

float Distance(float point1x , float point1y , float point2x , float point2y)
{
float distan;
distan = sqrt(pow(point2x - point1x , 2) +  pow(point2y - point1y , 2));
return(distan);
}

int AbsDistance(int point1x , int point1y , int point2x , int point2y)
{
int distan;
distan = abs(point2x - point1x) +  abs(point2y - point1y);
return(distan);
}

int Normal(int point)
{
if(point>0)
return(1);
if(point==0)
return(0);
if(point<0)
return(-1);
}


Now for some reason I get an error that I've defined each of the 3 func two times. The two lines of definition that it gives me for each one are the first and last{} of each func, does anyone know why? Thanks.

##### Share on other sites
I fail to reproduce this behavior on GCC. It compiles correctly, besides the obvious errors of including the deprecated iostream.h, stdio.h and math.h headers (use iostream, cstdio and cmath).

Could you provide either a minimal example that has the compile error, or give more source code related to it? EDIT: or the actual error messages.

##### Share on other sites
You can always stick the extern keyword in front of the function declarations in the header files. This should be unnecessairy, but give it a try.

##### Share on other sites
I assume a problem in your project (makefile or whatever) set-up. For some reason it seems that you compile that implementation file twice!?

##### Share on other sites

float Distance(float point1x , float point1y , float point2x , float point2y) {float distan;distan = sqrt((point2x-point1x)*(point2x-point1x) +              (point2y-point1y)*(point2y-point1y));return(distan);}

Never use pow to perform squaring - it's a complicated and slow function that needs to perform several slow floating point ops. Squaring can be done in a single operation due to common subexpression elimination.

##### Share on other sites
Quote:
 Original post by daniel_i_lHi, I'm working eith Dev and I have this strange problem, for the header file I have:*** Source Snippet Removed ***and for the file I have:*** Source Snippet Removed ***Now for some reason I get an error that I've defined each of the 3 func two times. The two lines of definition that it gives me for each one are the first and last{} of each func, does anyone know why?Thanks.

you're not #including MathDef.cpp anywhere by accident are you?

##### Share on other sites
I erased the files, wrote them again, and eveything worked!
That was pretty strange... thanks you guys for all your help!!