Hello,
i have a question about extending a class.
class ExString : public std::string {...};
now i want to implement some constructors.
i had this two:
1 2 3 4 5 6 7
|
ExString::ExString(const std::string &old)
: std::string(old)
{ }
ExString::ExString(const ExString &old)
: std::string(static_cast<std::string>(old))
{ }
|
then i removed the second one and my unit test of the copy constructor with an ExString-object still succeeds.
1 2 3 4 5
|
...
ExString es3("Cat");
ExString es4(es3);
BOOST_CHECK_EQUAL(es4 == es3, true);
...
|
so my question is:
when my class derives
one other class, is it enough to implement the copy constructor for an argument of the base class?
i would say yes (at least in this case), but im not sure.
Regards,
Mathes
Last edited on
The compiler gives you a default copy constructor that does a member-wise copy.
You shouldn't derive from std::string, however, as std::string is not meant to be a base class (ie, no virtual destructor).