I have a basic file I’m attempting to use.
#ifndef POINT_GUARD
#define POINT_GUARD
//------------------------------------------------------------------------------
struct Point {
int x, y;
Point(int xx, int yy) : x(xx), y(yy) { }
Point() :x(0), y(0) { }
};
//------------------------------------------------------------------------------
inline bool operator==(Point a, Point b) { return a.x==b.x && a.y==b.y; }
//------------------------------------------------------------------------------
inline bool operator!=(Point a, Point b) { return !(a==b); }
//------------------------------------------------------------------------------
#endif // POINT_GUARD
Notice that it’s wrapped in a guard. Now this is imported into two different files. I’m getting an error, though.
It complains as soon as it hits struct Point that it’s a “Redefinition of Point”. Any ideas what could be happening here?
I can’t reproduce the error with the input given. I placed your code in
test.h, and wrote this fortest.cpp:Running
g++ -Wall -c test.cppproduces no errors or warnings, and running it through the pre-processor shows thatstruct Pointis declared only once, so the guard is working.I’d guess there’s a declaration with the same name somewhere else, outside of the code you quoted?