views:

67

answers:

1

In a derived class I have a function called evaluate() (it's a virtual in the base class). In this derived class i also have a function set_value() and hence i want get_value() as well. get_value() should return the exact same thing as evaluate()

Is there anyway to say that a call to get_value is a call to evaluate()? With some sort of alias keyword?

I don't know if this exists or what it would be called, I have searched and nothing found.

Maybe I shoud do:

inline double Variable::get_value() const
{
    return evaluate();
}
+2  A: 

Nope, there are no aliases in C++ you're searching for. Sure, that is the way:

double Variable::get_value() const
{
    return evaluate();
}

On the other hand you could make get_value() function in a superclass and let it do the same thing if it is your design requirement.


The another advantage of implementing get_value() this way with bare hands is to provide an opportunity to involve additional logic. In case your evaluate() will get more and more CPU time you might implement simple caching in-place.

Keynslug
There is no advantage to using the inline keyword but using it adds complexity for the linker thus best advice is not to use unless it is needed.
Martin York