Jump to content


Photo

Let's Fight Ugly ::string


  • This topic is locked This topic is locked
3 replies to this topic

#1 guyver6

guyver6

    Captain

  • Xenocide Programming Department
  • 599 posts

Posted 10 January 2006 - 02:21 PM

Opening this topic to clean our code from uglyness of
::String
declarations. Now, thanks to that little code snippet, we no longer need to specify String's scope. ::String explicitly tells the compiler that we want String type that is defined in global scope (and that is our String type). Since two more projects we're using have classes with the same names, but in other namespaces (CEGUI::String and Ogre::String), this led to ambiguous symbol errors when one of us wanted to use
using namespace Ogre; // or CEGUI
to ease writting. Since our code is in Xenocide::Common/Core/UI namespaces, after saying using namespace Ogre in example, we had in our namespace equal access to String types defined in Ogre or CEGUI and in global scope. This led to errors when we had written String when declaring type. Solution was to explicitly specify which type we want to use, that is writting the ugly ::String stuff. This led to errors on GCC, since GCC treats <: as [, so we were forced to write
TemplateClass< ::String>
to make code portable. This all makes code unreadable.

So, now that the issue is fixed, and that even if you write using namespace Ogre; you have to explicitly tell Ogre::String, we can convert all ::String to String. So, I ask you, if you see somewhere ::String - change it to String and make sure code compiles. Also, if you see using namespace Ogre; or CEGUI in all definitions of methods of some class, move that to the beginning of .cpp file. Changing ::String to String can also be done in .h files. Btw, remember that it's forbidden to use using.... declarations in header files (the ones in commonrequisites.h are there to fix ::String issue so it doesn't count ;) ).

Greetings,
Guyver

Edited by guyver6, 10 January 2006 - 02:22 PM.

Posted Image
Sourceforge: guyver6
LinkedIn: Andrzej Haczewski
"A good business idea, they say, can be explained in one sentence. Similarly, each program entity should have one clear purpose."

Join #xenocide at irc.freenode.net.

#2 UnFleshed One

UnFleshed One

    Programming Department

  • Xenocide Inactive
  • 304 posts

Posted 10 January 2006 - 09:01 PM

Cheers for that one :)
Darkness is under the candle.

#3 Guest_Azrael_*

Guest_Azrael_*
  • Guests

Posted 10 January 2006 - 09:26 PM

Posted Image

#4 UnFleshed One

UnFleshed One

    Programming Department

  • Xenocide Inactive
  • 304 posts

Posted 11 January 2006 - 12:46 AM

I did a bit of purging, so now there are no ::Strings (One full rebuild more, one less... :)). It compiles and runs, but I might have replaced something extra, so keep your eyes open :)
Darkness is under the candle.