Changing member data in a derived class
Posted on 2004-03-28
If I have a virtual function in a derived class how do use it to change a member variable of the base class. I'm using an example that I've used recently on this site. Its basically a hierachy of computers, with the PC class being the base and Compaq's, Dells etc being the derived ones. I have function that needs to perform an update of the PC components. The components are basically base class pointers to seperate pc compoents. Therefore the overloaded upgraded function accepts a pointer for a new component as a paremeter and then needs to change the existing component pointer to that of the new component. when I try and access the pointer which is a private member variable of the base PC class I use a function that returns the pointer I need to update. Do I have to create another base member function called (swapPointer()) or something just to update the member variable or is their something else I can do.....