?
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Is there some way to get a function-pointer to the operators of the
builtin types? In the following example I have a generic function which
applies an operator on two values, however it does not work on builtin
types, is there a way to make this work?
struct Test
{
int i;
Test(int i_) : i(i_) { }
Test operator+(Test& t) { return Test(i + t.i); }
Test operator-(Test& t) { return Test(i - t.i); }
operator int() { return i; }
};
template<class T>
T operate(T& t1, T& t2, T (T::*func)(T&))
{
return (t1.*func)(t2);
}
int main() {
Test test1(1);
Test test2(2);
Test test3 = operate(test1, test2, &Test:perator+);
Test test4 = operate(test1, test2, &Test:perator-);
/*
int i1 = 1;
int i2 = 2;
int i3 = operate(i1, i2, ???);
int i4 = operate(i1, i2, ???)
*/
}
builtin types? In the following example I have a generic function which
applies an operator on two values, however it does not work on builtin
types, is there a way to make this work?
struct Test
{
int i;
Test(int i_) : i(i_) { }
Test operator+(Test& t) { return Test(i + t.i); }
Test operator-(Test& t) { return Test(i - t.i); }
operator int() { return i; }
};
template<class T>
T operate(T& t1, T& t2, T (T::*func)(T&))
{
return (t1.*func)(t2);
}
int main() {
Test test1(1);
Test test2(2);
Test test3 = operate(test1, test2, &Test:perator+);
Test test4 = operate(test1, test2, &Test:perator-);
/*
int i1 = 1;
int i2 = 2;
int i3 = operate(i1, i2, ???);
int i4 = operate(i1, i2, ???)
*/
}