#ifndef CLASS_fPOINT
#define CLASS_fPOINT
class fPOINT
{
public:
fPOINT(): x(0.0),y(0.0){};
float x;
float y;
};
#endif
2. Creating a separate file fPOINT.h with this declaration and making all of my other files include that one file (so if I use 1 file, I include it + fPOINT.h, if I use multiple files, I use them + fPOINT.h).
3. Instead of making my functions get fPOINTs as arguments, make them get float x and float y. this is a horrible idea though, because in one function I pass an array of fPOINT with a random number of variables. So I would now have to put two arrays of Xs and Ys. Also, when returning and fPOINT, I would have to now pass an X and a Y as pointers to change their values...
4. Any better idea ???
Thanks in advance
I just want a small advise...
OK, so I have a couple of include files I made myself! Basically they are math stuff and such. And I have that class I made, fPOINT which consists of two floats, x and y. Problem is that all of those includes use fPOINT and... they all declare it...
Basically, there is one class I use in ALL includes, but since I never know what include I''m gonna need, I declare it in all of them. Of course, problems starts when I include more than 1 of the files...
I tried to make the functions templates so I could declare fPOINT in my main CPP and just pass it in, but templates don''t work very well with includes and so I failed...
what''s the best solution?
1. Doing something like this:
The first one is known as multiple inclusion protection, and is the de facto way to handle the problem you're having. It's pretty much standard (although I don't know how technically accurate that is )
[edited by - Zipster on May 26, 2004 2:02:20 AM]
[edited by - Zipster on May 26, 2004 2:02:20 AM]
Yeah, that''s what I thought (I use the same thing for my includes).
But what would be the standard format for this? Like, for the whole file it would be:
#define NAMEOFFILE_H__
what about classes?
But what would be the standard format for this? Like, for the whole file it would be:
#define NAMEOFFILE_H__
what about classes?
If you''re on a *nix platform, just cat some of the headers in /usr/include. #define __file_h__ is pretty much the defacto standard from my experience, at least on *nix.
Additionally, make sure you really want a header as opposed to merely linking some code.
Additionally, make sure you really want a header as opposed to merely linking some code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement