B
balor
I have a class with a casting operator but GCC doesn't want to cast as
necessary and I'm wondering if this is legal or not.
class A {
public:
void test() {}
};
class Wrapper {
public:
Wrapper(A a) : a(a) {}
operator A &() { return a; }
private:
A a;
};
int main() {
A a;
Wrapper wrapper(a);
((A &)wrapper).test(); // works
wrapper.test(); // compile error
return 0;
}
Anyone have any idea whats wrong with wrapper.test()? The compiler
should be able to tell that if it casts to (A &), then a test() method
exists.
necessary and I'm wondering if this is legal or not.
class A {
public:
void test() {}
};
class Wrapper {
public:
Wrapper(A a) : a(a) {}
operator A &() { return a; }
private:
A a;
};
int main() {
A a;
Wrapper wrapper(a);
((A &)wrapper).test(); // works
wrapper.test(); // compile error
return 0;
}
Anyone have any idea whats wrong with wrapper.test()? The compiler
should be able to tell that if it casts to (A &), then a test() method
exists.