Jump to content
  • Advertisement
Sign in to follow this  
daniel_i_l

files

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites
And here's some other advice:


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 this post


Link to post
Share on other sites
Quote:
Original post by daniel_i_l
Hi, 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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!