Confused in choosing a declaration over other
-
Hi, I am confused regarding choosing one declaration from a set of two. I could not decided which one should be preferred over other and why it should be preferred. Please see the declarations below and let me know out of (I) and (II) which declaration is more preferred and why. (I) #if defined (UNICODE) && defined (_UNICODE) typedef std::wstring _tstring; #else typedef std::string _tstring; #endif (II) #if defined (UNICODE) && defined (_UNICODE) #define _tstring std::wstring #else typedef _tstring std::string; #endif Thanks and Regards :) :)
-
Hi, I am confused regarding choosing one declaration from a set of two. I could not decided which one should be preferred over other and why it should be preferred. Please see the declarations below and let me know out of (I) and (II) which declaration is more preferred and why. (I) #if defined (UNICODE) && defined (_UNICODE) typedef std::wstring _tstring; #else typedef std::string _tstring; #endif (II) #if defined (UNICODE) && defined (_UNICODE) #define _tstring std::wstring #else typedef _tstring std::string; #endif Thanks and Regards :) :)
I would choose
typedef
. You may google a bit [^] to find comparisons. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I am confused regarding choosing one declaration from a set of two. I could not decided which one should be preferred over other and why it should be preferred. Please see the declarations below and let me know out of (I) and (II) which declaration is more preferred and why. (I) #if defined (UNICODE) && defined (_UNICODE) typedef std::wstring _tstring; #else typedef std::string _tstring; #endif (II) #if defined (UNICODE) && defined (_UNICODE) #define _tstring std::wstring #else typedef _tstring std::string; #endif Thanks and Regards :) :)
Use the
typedef
. At least
typedef
s are part of the language and can be constrained by the namespacing mechanisms the language has (namespace
,class
,struct
etc).#define
s, on the other hand, have the effect of performing a global search and replace over your code, which can causes horrors to occur. The C++ FAQs say it[^] quite well.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p