I am developing a class. It's a pretty simple one.
The class has one data member which is a std::string.
The purpose of the class is simply to make sure that the string ends up having an even length.
The class is called a uid.
I'm a little confused.. should this just inherit from std::string ie
class uid:public std::string ?
I'm not sure I'm handling the copy constructors properly.
Code:class uid { private: std::string id; public: uid(std::string _id) { id = _id; if (id.size() & 1) // is the length odd? id.append(" "); // yes. Now the length should be even } uid& operator=(std::string& _id) // Is this method necessary? { id = _id; if (id.size() & 1) // is the length odd? id.append(" "); } uid& operator=(uid& _id) { id = _id; } ~uid(void) { // Nothing to do really. } int getSize(void) { return id.size(); } const void *getData(void) { return id.c_str(); } };




Reply With Quote