Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Confused in choosing a declaration over other

Confused in choosing a declaration over other

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ComplexLifeForm
    wrote on last edited by
    #1

    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 :) :)

    CPalliniC S 2 Replies Last reply
    0
    • C ComplexLifeForm

      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 :) :)

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • C ComplexLifeForm

        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 :) :)

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        Use the

        typedef

        . At least typedefs are part of the language and can be constrained by the namespacing mechanisms the language has (namespace, class, struct etc). #defines, 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups