namespace problem win32

Started by
2 comments, last by YellowMaple 18 years, 3 months ago
Okay I'm still quite new to win32 programming, but it seems that in order to include gl.h you need to include windows.h as well. What a pain... on top of that, I have a class called Polygon, but it would seem that microsoft has already defined some sort of Polygon class or structure. I would like to keep my Polygon class that I have created myself so I tried using namespaces but am running into problems. Here is a rough outline of what I have: Polygon.h:

namespace myNameSpace{
  class Polygon{
    ...
  };
}
Polygon.cpp:

using namespace myNameSpace;

...
<function definitions>
...
PolygonModel.h:

using namespace myNameSpace;

class PolygonModel{
  public:
    ...
    void setPolygons(Polygon* _polys);
    ...
  private:
    Polygon* polys;
    ...
};
PolygonModel.cpp

using namespace myNameSpace;

...
<function definitions>
...
When I try to compile PolygonModel however, I get messages complaining about 'ambiguous symbol Polygon' or 'syntax error: identifier Polygon'. Any ideas? I tried a couple of variations with the name spaces and if I do myNameSpace::Polygon for every occurence of the string Polygon in PolygonModel.cpp things work out but this is ugly :p I would like to just declare the namespace at the beginning and be able to refer to myNameSpace::Polygon as just plain 'Polygon' throughout the file...
Advertisement
Get rid of the 'using namespace myNameSpace;'

The above dumps everything in myNameSpace into the global namespace, which leads you right back to your original problem, when you write Polygon the compiler can't figure out which one you mean. Instead of the above, do myNameSpace::Polygon everywhere you mean your Polygon type, and Polygon whenever you mean the windows.h Polygon type.
Polygon is the name of a Win32 drawing routine. In order to solve this problem, either you have to modify your class name or you put class in front of the variable name like this:

void setPolygons(class Polygon* _polys);

I would suggest rename your class if possible, by the way.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Thanks for the replies! I suppose renaming my class would be the best solution given what you guys have told me... thanks again :)

This topic is closed to new replies.

Advertisement