problems using inheritance
I am new to C++ and have the following problem. I create a class A from which I derive several other classes B1, B2, ... via inheritance. A member function f of A computes a specific value (property) V of the things I am dealing with. B1, B2, ... all have this property. I thought, "Thank god there is inheritance, now I don't have to write the same member function again and again for every B class." However, the property I am computing in this member function depends on another property specific to the derived classes. Lets call this property P... so P(B1) is different from P(B2) etc. In the main I want to initialize objects from the derived classes b1, b2 etc and call b1.f, b2.f etc. I need to achieve that this function now uses the specific properties P(B1), P(B2) of the derived classes and not the one of the basis class. As f is defined in the scope of A it always uses P(A).
My constraints are:
1. the function cannot take further input arguments (no objects by reference etc)
2. I don't want to redefine f in all of the derived classes (I want f not to appear in the definition of the derived classes).
I hope this makes sense. Thanks for your help guys.