C
Craig Sanders
Hello all.
I'm hoping that someone might please be able to help me out.
Does anyone know if it is possible to pass object member functions (as
opposed to class member functions) as the 4th and 5th arguments to the
inner_product function?
class
TestClass
{
// Various function declarations omitted for brevity.
int sumFunction(int a, int b)
{
return(a + b);
}
int productFunction(int a, int b)
{
return(a * b);
}
};
int main(void)
{
// Assume vectorA and vectorB are created and populated with
values.
TestClass testClass;
cout << "Result = " <<
inner_product
(
vectorA.begin(),
vectorA.end(),
vectorB.begin(),
testClass.sumFunction,
testClass.productFunction
) <<
endl;
return(0);
}
I can't seem to get main to compile for the case shown above. However,
if sumFunction and productFunction are turned into class functions,
i.e. by prepending their definition with the keyword static, then I
can get main to compile and work. Is anyone able to tell me why this
is the case and how I can get inner_product to work with object
functions?
Thanks in advance.
- Craig
I'm hoping that someone might please be able to help me out.
Does anyone know if it is possible to pass object member functions (as
opposed to class member functions) as the 4th and 5th arguments to the
inner_product function?
class
TestClass
{
// Various function declarations omitted for brevity.
int sumFunction(int a, int b)
{
return(a + b);
}
int productFunction(int a, int b)
{
return(a * b);
}
};
int main(void)
{
// Assume vectorA and vectorB are created and populated with
values.
TestClass testClass;
cout << "Result = " <<
inner_product
(
vectorA.begin(),
vectorA.end(),
vectorB.begin(),
testClass.sumFunction,
testClass.productFunction
) <<
endl;
return(0);
}
I can't seem to get main to compile for the case shown above. However,
if sumFunction and productFunction are turned into class functions,
i.e. by prepending their definition with the keyword static, then I
can get main to compile and work. Is anyone able to tell me why this
is the case and how I can get inner_product to work with object
functions?
Thanks in advance.
- Craig