Axel Freyn wrote:
There is also another possibilty you could maybe think about: If you
create an additional structure, which "caches" the pointer to A or B and
returns references to it, you can have this new structure living on the
stack - and do with it whatever you want (e.g. you can insert it into a
std::vector without problems):
struct Cache{
Cache( A* _a):a(_a){}
A *a;
A& operator()(){ return *a;}
};
I like this whole thing, but wouldn't operator* be more natural to
return the reference?
Patrick