What is the relationship between foo and bar ? If they have external linkage, you can write something like:
extern Foo foo; extern Bar bar; Foo foo( bar ); Bar bar( foo );
(I assume these are constructors that set a parameter reference.)
This assumes a namespace space and a static lifetime, of course (but an anonymous namespace is fine).
If they are members of a class, then there is no problem:
class Together { Foo foo; Bar bar; public: Together() : foo( bar ), bar( foo ) {} };
If they are local variables (without binding), I don't think there is a solution.
EDIT:
Actually, local variables have a simple solution: just define a local class that has them as members and use it.
source share