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. How to do this????

How to do this????

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
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.
  • E Offline
    E Offline
    eli15021979
    wrote on last edited by
    #1

    Hi, i know that i can set each of the incoming parameters of my function to a default value, like this:

    void Function(int x , int y = 10);

    and then,i can call to the function in 2 ways:

    Function(10,20); //x = 10 , y = 20
    Function(10); //x = 10 , y = 10

    my question is - how can i set a CString object to empty by default? for example:

    void Function(int x , CString string = ???????);

    and call that function:

    Function(10,"Not an empty string"); // x = 10 , string = "Not an empty string"
    Function(10); // x = 10 , string = string.Empty()

    anyone????????:doh: Regards, Eli

    R T B 3 Replies Last reply
    0
    • E eli15021979

      Hi, i know that i can set each of the incoming parameters of my function to a default value, like this:

      void Function(int x , int y = 10);

      and then,i can call to the function in 2 ways:

      Function(10,20); //x = 10 , y = 20
      Function(10); //x = 10 , y = 10

      my question is - how can i set a CString object to empty by default? for example:

      void Function(int x , CString string = ???????);

      and call that function:

      Function(10,"Not an empty string"); // x = 10 , string = "Not an empty string"
      Function(10); // x = 10 , string = string.Empty()

      anyone????????:doh: Regards, Eli

      R Offline
      R Offline
      Rahim Rattani
      wrote on last edited by
      #2

      As smple as u set the integer values. void Function( int x , CString string = "" ); Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

      1 Reply Last reply
      0
      • E eli15021979

        Hi, i know that i can set each of the incoming parameters of my function to a default value, like this:

        void Function(int x , int y = 10);

        and then,i can call to the function in 2 ways:

        Function(10,20); //x = 10 , y = 20
        Function(10); //x = 10 , y = 10

        my question is - how can i set a CString object to empty by default? for example:

        void Function(int x , CString string = ???????);

        and call that function:

        Function(10,"Not an empty string"); // x = 10 , string = "Not an empty string"
        Function(10); // x = 10 , string = string.Empty()

        anyone????????:doh: Regards, Eli

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        eli15021979 wrote: my question is - how can i set a CString object to empty by default? for example: void Function(int x , CString string = ???????); and call that function: Function(10,"Not an empty string"); // x = 10 , string = "Not an empty string" why don't you do the same as you code with integers...?

        void Function(int x , CString string = "");

        Then you call it the way you like...

        Function(10, "Hello CP"); // Function(10, "")
        Function(10); // Function(10, "Hello CP")


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        1 Reply Last reply
        0
        • E eli15021979

          Hi, i know that i can set each of the incoming parameters of my function to a default value, like this:

          void Function(int x , int y = 10);

          and then,i can call to the function in 2 ways:

          Function(10,20); //x = 10 , y = 20
          Function(10); //x = 10 , y = 10

          my question is - how can i set a CString object to empty by default? for example:

          void Function(int x , CString string = ???????);

          and call that function:

          Function(10,"Not an empty string"); // x = 10 , string = "Not an empty string"
          Function(10); // x = 10 , string = string.Empty()

          anyone????????:doh: Regards, Eli

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          Also, you need to decide if the function accepting the CString really REQUIRES a CString object. Maybe you can get by with a LPCTSTR instead. Then you can write your function: void Function(int x , LPCTSTR szString = NULL); and call that function: Function(10, "Not an empty string"); // x = 10 , szString != NULL Function(10); // x = 10 , szString = NULL You can get really tweaked after awhile working with code all written to accept a CString by value, and then when you examine the function's use of the string, it could have easily sufficed to send it a string constant instead.

          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