S
SpreadTooThin
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 it simple to make sure that the string that
is used as a constructor has an even length.
The class is called a uid.
I'm a little confused.. should this just inherit from std::string ie
class uidublic std::string ?
I'm not sure I'm handling the copy constructors properly.
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)
{
id = _id;
if (id.size() & 1) // is the length odd?
id.append(" ");
}
uid& operator=(uid& _id)
{
id = _id;
}
~uid(void)
{
// Nothing to do really.
}
};
The class has one data member which is a std::string.
The purpose of the class it simple to make sure that the string that
is used as a constructor has an even length.
The class is called a uid.
I'm a little confused.. should this just inherit from std::string ie
class uidublic std::string ?
I'm not sure I'm handling the copy constructors properly.
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)
{
id = _id;
if (id.size() & 1) // is the length odd?
id.append(" ");
}
uid& operator=(uid& _id)
{
id = _id;
}
~uid(void)
{
// Nothing to do really.
}
};