Sign in to follow this  

namespace problem win32

This topic is 4361 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

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...

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 4361 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this