JamesJ,
That's the general idea, except for one small but important mistake: classes default their members to private, so all your attributes are invisible to their derived classes. In your example above, before all your member variables you should have the "public:" or "protected:" keywords.
Also (but this is unrelated to the initial issue of the relationship of derived classes with private/protected/public members of their parent classes), one of the reasons behind classes in the first place is to provide some encapsulation, keeping the internal implementation (i.e. the data representing the class) hidden away from direct manipulation, accesing them through member functions. This allows you to protect the integrety of the class's data, and will also allow you to change the types of member variables used without breaking any code that has already been written using that class. For example:
</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">class CBeing
{
protected: // main() cannot see these
BOOL Alive;
short Age;
private:
void InitBaseClassAttributes();
public:
CBeing();
CBeing(BOOL init_alive, int init_age);
virtual ~CBeing();
void SetAlive(BOOL set_alive = TRUE);
void SetAge(int set_age);
BOOL GetAlive();
int GetAge();
};
// constructor for default initialization
CBeing::CBeing()
{
InitBaseClassAttributes();
}
CBeing::CBeing(BOOL init_alive, int init_age)
{
// start in a known state
InitBaseClassAttributes();
// then change to reflect desired init state
SetAlive(init_alive);
SetAge(init_age);
}
// private member function, call only be called from other member functions of this class
void CBeing::InitBaseClassAttributes()
{
Alive = TRUE;
Age = 0;
}
CBeing::~CBeing()
{
// nothing to do here yet
}
void SetAlive(BOOL set_alive /*= TRUE*/)
{
Alive = set_alive;
}
void SetAge(int set_age)
{
// disallow negative ages, protect the data
if(set_age) >= 0)
Age = (int)set_age;
}
BOOL GetAlive()
{
return Alive;
}
int GetAge()
{
return (int)Age;
}
int main()
{
CBeing person; // defaults to alive and age of 0
CBeing tree(FALSE, 89); // create a dead 89-year old tree
person.SetAge(18);
if(tree.GetAlive() == TRUE)
{
printf("The tree is alive!\n"

;
}
else
{
printf("The tree is dead!\n"

;
}
return 0;
}</pre>[/QUOTE]In this example, if later on I decide to change the internal implementation of "Age" from a short to a float, I only have to change its declaration and a couple of typecasts in the member functions: no code (e.g. in main() or elsewhere) that is already written needs to change. Also note that it is now impossible to have a negative Age in a CBeing (we have protected our data from invalid conditions), because the variable is not accessible outside the class and because our member function prevents changing the Age if the new age is < 0.
Also, you should use constructors, destructors, as I have above. It's only beneficial.