On Sun, 18 Dec 2005 19:26:04 +0100, Raf256 <sp**@raf256.com.invalid>
wrote:
Hi,
I would extend class only a bit. In example: I want to write my own class,
that works all like std::string, only it also have member int mDatabase;
and it have method SaveToDatabase();
I could do like:
class cStorableStr : std::string {
private:
int mDatabase;
public:
std::string::operator=;
void SaveToDatabase();
};
that inherits all methods from std::string, and operator(s) =.
But what if I would like to just unherit ALL. ALL operators, or ALL
members+operators. Is there a syntax allowing that?
Like:
public: std::string::*;
If not, perhaps it would be nice to have it?
You should inherit publicly from string, and then write the
non-inheritable member functions: default constructor, copy
constructor and copy assignment, and supply the assignment of string
and constructor from string:
class cStorableStr : std::string {
private:
int mDatabase;
public:
enum {default_mDatabase=;}0;
cStorableStr():mDatabase(default_mDatabase) {}
cStorableStr(const cStorableStr& other)
:std::string(other),mDatabase(other.mDatabase) {}
cStorableStr& operator=(const cStorableStr& other)
{std::string::operator=(other);mDatabase=other.mDa tabase;}
cStorableStr& operator=(const std::stringr& other)
{std::string::operator=(other);mDatabase=default_m Database;}
void SaveToDatabase();
};
Be careful when using this class, as std::basic_string does not have a
virtual destructor.
Regards
-- Zara