J
J Solowiej
Hi,
I am wondering: is it possible to pass pointer to member function (non
static) to initialize another class? For exmaple:
class X {
public:
typedef double (*F)(double);
X(F f) : f_(f) {}
private:
F f_;
};
class Y {
public:
Y() { t=1.0; X x(&Y::g);}
private:
double t;
double g(double x) {
return(x+t);
}
};
int main() {
Y y;
return(0);
}
wont's compile, g++ (3.2) gives the following messages:
In constructor `Y::Y()': no matching function for call to
`X::X(double (Y::*)(double))' : candidates are: X::X(const X&),
X::X(double (*)(double))
Thanks.
I am wondering: is it possible to pass pointer to member function (non
static) to initialize another class? For exmaple:
class X {
public:
typedef double (*F)(double);
X(F f) : f_(f) {}
private:
F f_;
};
class Y {
public:
Y() { t=1.0; X x(&Y::g);}
private:
double t;
double g(double x) {
return(x+t);
}
};
int main() {
Y y;
return(0);
}
wont's compile, g++ (3.2) gives the following messages:
In constructor `Y::Y()': no matching function for call to
`X::X(double (Y::*)(double))' : candidates are: X::X(const X&),
X::X(double (*)(double))
Thanks.