H
Hamish
Hi,
The following doesn't compile (using g++ 4.0.3 with all warnings, -
pedantic, -ansi, etc.):
class X {
public:
int f(int i = 0) { return i; }
};
int main() {
int (X::*blah)() = &X::f; // Invalid conversion.
X x;
return (x.*blah)();
}
I always thought that specifying default arguments (like above) was a
kind of shorthand for something like:
class X {
public:
int f(int i) { return i; }
int f() { return f(0); }
};
int main() {
int (X::*blah)() = &X::f; // Okay now.
X x;
return (x.*blah)();
}
Is there a way to get the behaviour of the second code snippet while
using default arguments like in the first code snippet?
Cheers,
Hamish.
The following doesn't compile (using g++ 4.0.3 with all warnings, -
pedantic, -ansi, etc.):
class X {
public:
int f(int i = 0) { return i; }
};
int main() {
int (X::*blah)() = &X::f; // Invalid conversion.
X x;
return (x.*blah)();
}
I always thought that specifying default arguments (like above) was a
kind of shorthand for something like:
class X {
public:
int f(int i) { return i; }
int f() { return f(0); }
};
int main() {
int (X::*blah)() = &X::f; // Okay now.
X x;
return (x.*blah)();
}
Is there a way to get the behaviour of the second code snippet while
using default arguments like in the first code snippet?
Cheers,
Hamish.