Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Any gain using ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 9311 of 10094
Post > Topic >>

Any gain using a global const std::string for empty strings?

by "Michael S." <misuo@[EMAIL PROTECTED] > Feb 25, 2008 at 12:05 AM

Hi,

In some of our wast set of C++ source files I've seen some code
which uses a global const std::string as illustrated in the following
code:

  // file: strutil.hpp
  #include <string>
  extern const std::string EmptyString;

  // file: strutil.cpp
  #include "strutil.hpp"
  const std::string EmptyString;

  // file: file1.hpp
  #include "strutil.hpp"

  class A
  {
  public:
    void foo( int money, const std::string & name = EmptyString );
    virtual std::string boo() { return EmptyString; }
  };
  ...

Are the use of the global EmptyString constant really necessary?
Are there any performance/optimization gain of doing this, instead
of simply using std::string() as illustrated by:

  class A
  {
  public:
    void foo( int money, const std::string & name = std::string() );
    virtual std::string boo() { return std::string(); }
  };
  ...


Thanks in advance for all replies,
/Michael


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 13 Posts in Topic:
Any gain using a global const std::string for empty strings?
"Michael S." &l  2008-02-25 00:05:46 
Re: Any gain using a global const std::string for empty strings?
Carl Barron <cbarron41  2008-02-25 05:49:43 
Re: Any gain using a global const std::string for empty strings?
Alberto Ganesh Barbati &l  2008-02-25 16:16:40 
Re: Any gain using a global const std::string for empty strings?
"Alf P. Steinbach&qu  2008-02-25 16:12:10 
Re: Any gain using a global const std::string for empty strings?
"Bo Persson" &l  2008-02-25 16:14:18 
Re: Any gain using a global const std::string for empty strings?
peter koch larsen <pet  2008-02-26 12:42:57 
Re: Any gain using a global const std::string for empty strings?
Jeff Schwab <jeff@[EMA  2008-02-27 01:44:30 
Re: Any gain using a global const std::string for empty strings?
j_richter@[EMAIL PROTECTE  2008-02-27 18:12:16 
Re: Any gain using a global const std::string for empty strings?
peter koch larsen <pet  2008-02-28 05:13:19 
Re: Any gain using a global const std::string for empty strings?
Anders Dalvander <goog  2008-02-28 05:31:05 
Re: Any gain using a global const std::string for empty strings?
Craig Scott <audiofana  2008-02-28 05:31:23 
Re: Any gain using a global const std::string for empty strings?
"Bo Persson" &l  2008-02-28 17:09:56 
Re: Any gain using a global const std::string for empty strings?
peter koch larsen <pet  2008-02-29 04:39:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:12:08 CDT 2008.