How to simplify repetetive constructor calls?
I have a following situation: class X { type1 v1; type2 v2; ... typen vn; other_var ... public: X() : v1(this), v2(this), .., vn(this), other_var(1, 2, 3) { } }; I'm looking for suggestions on how to automatically initialize variables v1..vn with "this" being passed as the only argument to their constructor. In the ideal case, the programmer should not need to specify any constructor calls for v1..vn, so that the end result looks something like: class X { type1 v1; ... typen vn; other_var; public: X() : other_var(1, 2, 3) { // some "magic" arranges that v1(this) .. vn(this) is called } }; Thanks!
Zeljko Vrba a écrit :
I have a following situation:
class X { type1 v1; type2 v2; ... typen vn; other_var ... public: X() : v1(this), v2(this), .., vn(this), other_var(1, 2, 3) { } };
I'm looking for suggestions on how to automatically initialize variables v1..vn with "this" being passed as the only argument to their constructor. In the ideal case, the programmer should not need to specify any constructor calls for v1..vn, so that the end result looks something like:
class X { type1 v1; ... typen vn; other_var; public: X() : other_var(1, 2, 3) { // some "magic" arranges that v1(this) .. vn(this) is called } };
Can't a boost::tuple
Le Ven 6 juin 2008 07:43, Zeljko Vrba a écrit :
On Thu, Jun 05, 2008 at 01:38:04PM +0200, Joel Falcou wrote:
Can't a boost::tuple
with a custom, recursive constructor
function do the trick ?
Seems like a good idea, if I get the "recursive constructor" part working :-)
Something like:
class value_tuple : public tuple
participants (3)
-
joel falcou
-
Joel Falcou
-
Zeljko Vrba