It sounds like you want to use function objects or function pointers. (On second thought, you never want to use function pointers in C++)
Here's an example using templates.
Code:
template <class T> bool myfunc(bool lv, bool rv, T oper)
{
return oper(lv, rv);
}
struct Or
{
bool operator()(bool lv, bool rv)
{
return lv || rv;
}
};
int main()
{
bool result = myfunc(true, false, Or());
return 0;
}
Here's the same thing using inheritance
Code:
struct LogicalOperator
{
virtual bool operator()(bool lv, bool rv) const = 0;
};
struct Or: public LogicalOperator
{
bool operator()(bool lv, bool rv) const
{
return lv || rv;
}
};
bool myfunc(bool lv, bool rv, const LogicalOperator& oper)
{
return oper(lv, rv);
}
int main()
{
bool result = myfunc(true, false, Or());
return 0;
}
I have the feeling you won't understand all of this, so don't be afraid to ask questions.