What you're doing is a little awkward, but technically fine (except for leaking memory by not deleting name and value in the assignment operator before new[]
-ing it), however only if you have no plans for multiple inheritance. That gets a bit messy, and may be why whatever books you're referring to are warning against it, but you shouldn't be using multiple inheritance (in general, but especially) on classes with data members anyways.
You might want to try a different approach regardless. Consider using a protected helper function (or a few) in the base class to set its variables:
class A
{
public:
// ...
private:
char *value;
protected:
void set_value(const char *str)
{
delete[] value; // remember, deleting null does nothing
value = new char[strlen(str)+1];
strncpy(value, str, strlen(str)); // Also, why do you need strncpy?
// You'll get no null-terminator, which leads to major problems
// Consider just strcpy(value, str);
}
};
This way, you can set that value from any derived class, the functionality is still hidden from public use, and you don't have to write an assignment operator or copy constructor for an abstract class. Which, when you think about it, really doesn't make much sense, does it?
It also saves you from this:
A *a = new B;
B *b = new B;
(*a) = (*b); // ...with an assignment operator on A, this should compile.