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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Initializing CString in constructor

How to Initializing CString in constructor

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 4 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.
  • K Offline
    K Offline
    krishnakumartm
    wrote on last edited by
    #1

    Hi I have a CString variable in my class like bellow i want to initialize it to nothing which way is best Here i listed two ways. If any way is best why? class MyClass { CString name; MyClass() { name = _T(""); //way 1 name.Empty(); //way 2 } } Thanks in advance

    ---------------------------- KRISHNA KUMAR T M

    M C 2 Replies Last reply
    0
    • K krishnakumartm

      Hi I have a CString variable in my class like bellow i want to initialize it to nothing which way is best Here i listed two ways. If any way is best why? class MyClass { CString name; MyClass() { name = _T(""); //way 1 name.Empty(); //way 2 } } Thanks in advance

      ---------------------------- KRISHNA KUMAR T M

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      what about

      MyClass() : name(_T(""))
      {
      }

      1 Reply Last reply
      0
      • K krishnakumartm

        Hi I have a CString variable in my class like bellow i want to initialize it to nothing which way is best Here i listed two ways. If any way is best why? class MyClass { CString name; MyClass() { name = _T(""); //way 1 name.Empty(); //way 2 } } Thanks in advance

        ---------------------------- KRISHNA KUMAR T M

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        As far as i know CString's default constructor initializes it to an empty string anyways, so you don't have to do that explicitly. Or am i wrong?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. <

        M 1 Reply Last reply
        0
        • C Code o mat

          As far as i know CString's default constructor initializes it to an empty string anyways, so you don't have to do that explicitly. Or am i wrong?

          > The problem with computers is that they do what you tell them to do and not what you want them to do. <

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Code-o-mat wrote:

          CString's default constructor initializes it to an empty string anyways, so you don't have to do that explicitly.

          Indeed!

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          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