In C++, is there any way to have something like a temporary variable in an initialization list. I want to initialize two constant members with the same instance of something
In C++11 you could use delegating constructors:
class Baz{ const Foo f; const Bar b; Baz(Paramaters p) : Baz(p, temp(p)) { } // Delegates to a private constructor // that also accepts a Something private: Baz(Paramaters p, Something const& temp): f(p,temp), b(p,temp) { // Whatever } };