Page 1 of 1

Rename Ogre::map before official 1.7 release?

Posted: Sat Feb 20, 2010 8:30 pm
by Calder
It's only a mild inconvenience, but Ogre's map declaration interferes with STL map. This means that any files having:

Code: Select all

using namespace std
using namespace Ogre
cannot use the map class because line 497 of OgrePrerequisites.h conflicts with it. Anyway, a small nuisance but generally Ogre's pretty good about avoiding name-clashes with the STL so I thought I'd mention it.

EDIT: Just ran into the same problem with Ogre::vector. I'm going through the process of updating my code to Ogre 1.7 right now so I might keep posting these. Hopefully not though...

Re: Rename Ogre::map before official 1.7 release?

Posted: Sat Feb 20, 2010 9:51 pm
by SigfriedMcWild
You really shouldn't be using using directives ("using namespace x;"). Using them ends up defeating the point of namespaces, as you are finding out.

In headers you should always use the fully qualified names, in source files you could use using declarations ("using x::y;") to selectively import things that you use.

Re: Rename Ogre::map before official 1.7 release?

Posted: Sat Feb 20, 2010 10:19 pm
by MrD
Those are there for a reason, they provide you with STL containers that default to using OGREs STL memory allocator.

As has been stated, 'using namespace' isn't really good practice for anything general and is especially bad in header files since it cascades and causes namespace pollution. The only thing I ever use 'using namespace' for is inside the CPP files and for my own namespaces; any third party libraries like OGRE and the STL I always explicitly qualify regardless of whether they are in a header or in a source file.

Re: Rename Ogre::map before official 1.7 release?

Posted: Sun Feb 21, 2010 4:59 pm
by sinbad
What the others said. We won't be changing this.

"using namespace" should always be used with care, but in particular, "using namespace std" is extremely bad form in all but the tightest scopes, best to get it out of your code now. The std namespace includes lots of common words which are guaranteed to clash with something eventually.

Re: Rename Ogre::map before official 1.7 release?

Posted: Mon Feb 22, 2010 2:23 am
by Calder
Ok, thanks for the replies! I'll fix my code if this is such bad practice.

Re: Rename Ogre::map before official 1.7 release?

Posted: Mon Feb 22, 2010 2:41 am
by jacmoe
If you want, use this:

Code: Select all

using namespace_name::thing;
Like for std::string, etc.
It's much better.