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)
- you not need pointer string. reference better - hence
&
- your constructor should not modifying string - tell both compiler , developer - hence
const
- do not pollute namespace - hence
std::
- do not use
using std
(see 3)
Comments
Post a Comment