c++ - trouble with passing a string pointer and then checking size in a constructor/method -


i'm still learning strings, i'm trying use them more often. how work? i'm not sure start (yes, object. i'm learning these atm assignment)

myclass::myclass(string* newname) {   if (newname.length() > maxnamelength) //maxnamelength = 50   {        //do stuff   } } 

here little explanation use

myclass::myclass(const std::string& newname) 
  1. you not need pointer string. reference better - hence &
  2. your constructor should not modifying string - tell both compiler , developer - hence const
  3. do not pollute namespace - hence std::
  4. do not use using std (see 3)

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -