T
Tom Smith
Hi,
What I want to do is rather complicated to describe but simple to demonstrate:
so I'll do that instead.
The following doesn't compile. Is there a a way to make it work? (by "make it
work", I mean: can I write the classes A, B and C in such a way that the given
main function will compile and do what I expect).
Cheers,
Tom
#include <iostream>
using namespace std;
class A
{
void function() { cout << "function called!"; }
};
class B
{
};
class C
{
operator A& () { return a; }
operator B& () { return b; }
A a;
B b;
};
int main()
{
C c;
c.function(); // I'd like this to automatically convert C to an A
}
What I want to do is rather complicated to describe but simple to demonstrate:
so I'll do that instead.
The following doesn't compile. Is there a a way to make it work? (by "make it
work", I mean: can I write the classes A, B and C in such a way that the given
main function will compile and do what I expect).
Cheers,
Tom
#include <iostream>
using namespace std;
class A
{
void function() { cout << "function called!"; }
};
class B
{
};
class C
{
operator A& () { return a; }
operator B& () { return b; }
A a;
B b;
};
int main()
{
C c;
c.function(); // I'd like this to automatically convert C to an A
}