S
spongejon
I'm trying to write some code which uses a proxy to be able to catch
member functions calls through a pointer.
The following code won't compile due to A being an abstract class and
Proxy doesn't explicitly implement A's interface. However Proxy
behaves like A, if the member function is called through a pointer to
a Proxy object.
Has anyone tried to implement anything like this?
class A
{
public:
virtual void doit() = 0;
};
class B : public A
{
public:
virtual void doit(){}
};
class Proxy : public A
{
public:
Proxy (B *b):_b(b){}
B* operator->()
{
return _b;
}
private:
B* _b;
};
int main(int argc, char *argv[])
{
B b;
Proxy p(&b);
p->doit();
}
member functions calls through a pointer.
The following code won't compile due to A being an abstract class and
Proxy doesn't explicitly implement A's interface. However Proxy
behaves like A, if the member function is called through a pointer to
a Proxy object.
Has anyone tried to implement anything like this?
class A
{
public:
virtual void doit() = 0;
};
class B : public A
{
public:
virtual void doit(){}
};
class Proxy : public A
{
public:
Proxy (B *b):_b(b){}
B* operator->()
{
return _b;
}
private:
B* _b;
};
int main(int argc, char *argv[])
{
B b;
Proxy p(&b);
p->doit();
}