Header Prefixes and Linking

I'm creating a set of classes to handle polygons and other geometric objects. Original plan was to have three classes: PolygonVertex, PolygonEdge, and Polygon. PolygonEdge is made up of two PolygonVertices and Polygon is made up of an arbitrary number of PolygonEdges. Coding everything went smoothly, used header guards for Vertex and Edge, etc.

Then I tried to include Polygon in another header. If I have the header named "Polygon.h" VS2008 fails to link; I get error C2146 and error C4430, which boils down to "your function doesn't have a return type, and it can't be int by default." If I use PolygonEdge or PolygonVertex, it recognizes both of them. If I rename the class to something like PolygonA it works. But if the class is named Polygon it refuses to recognize that Polygon is a class.

Whats going on here? I can fix it by renaming my Polygon class to something other than just Polygon, but I've never ran into this problem before and I haven't read about it either. It's acting as if I have a header prefix, say ABC with classes ABCdef and ABCmnb, then I can't have a class ABC.
fails to link; If I have the header named "Polygon.h" VS2008 fails to link; I get error C2146 and error C4430,


Those are compiler errors, not linker errors.

Anyway the problem is because "Polygon" is also a WinAPI function, so you have a name conflict:

http://msdn.microsoft.com/en-us/library/dd162814(v=VS.85).aspx

You'll need to either not use WinAPI, or name your class something else.

Unfortunately, since many WinAPI functions are actually macros in disguise, even putting your code in a namespace might not work (although I guess you could undef Polygon)
I would first try not including windows.h in the header. If that's not possible, #undef. If it's not a macro, then rename.
Yup, it was the naming conflict. Didn't actually think of checking for that, changing the name of my class fixed it.
Topic archived. No new replies allowed.