Pointer to a function in class

Hi
I have problem at pointing to the function at the class structure.
To demonstrate my problem,I have written a simple code.
I have two function.
''Xsquared'' returns square of input value.
''multipleby4'' multiplies by 4 of input value.

The pointer to the Xsquared is the input value of the multipleby4.



#include <cmath>
#include <iostream>

using namespace std;

class Int
{
public:
Int( int);
double xSquared(double x);
double multipleby4(double (*F)(double));

void CreateInt();
private:
int a;
int result;
};
Int::Int( int b)
:a(b)
{
CreateInt();
}
double Int::xSquared(double x)
{
// power function, can be replaced with x * x
return pow(x, 2);
}
double Int::multipleby4(double (*F)(double))//Problem at this stage
{
double value = 4 * (*F)(a);
return (value);
}

void Int::CreateInt()
{
result = multipleby4(xSquared);
}
int main()
{
Int ss(2);

return(0);
}#include <cmath>
#include <iostream>

using namespace std;

class Int
{
public:
Int( int);
double xSquared(double x);
double multipleby4(double (*F)(double));

void CreateInt();
private:
int a;
int result;
};
Int::Int( int b)
:a(b)
{
CreateInt();
}
double Int::xSquared(double x)
{
// power function, can be replaced with x * x
return pow(x, 2);
}
double Int::multipleby4(double (*F)(double))//Problem at this stage
{
double value = 4 * (*F)(a);
return (value);
}

void Int::CreateInt()
{
result = multipleby4(xSquared);
}
int main()
{
Int ss(2);

return(0);
}
[/code]



Complers errors are;
39: no matching function for call to `Int::multipleby4(<unknown type>)'
Last edited on
Function pointers and [i]member function[i] pointers are two different things.

The type of double Int::xSquared( double ) is

double (Int::*func)( double )

not

double (*func)( double )


Topic archived. No new replies allowed.