Thread: What is a better style?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    65

    What is a better style?

    I have some functions which perform string transformations. Since they use the original string, but return a copy of the modified string, what is better style?
    Code:
    string transform1(const string& s) { //uses const reference
    	string s2 = s; //make a copy
    	//do some stuff on the copy
    	return s2;
    }
    
    string transform2(string s) { //passed by value
    	//do some stuff on the copy already passed in
    	return s;
    }
    Last edited by jw232; 09-14-2008 at 10:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Which style of if loops is most common?
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 08-25-2005, 03:18 PM
  4. WS_EX_COMPOSITED style (double buffering) problems
    By JasonD in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2004, 11:21 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM