I want to write a code in c++ so that the I can initialize a class using a constructor with unknown number of parameters. I have an array in my class and i want to store all the values that i pass to my constructor to be stored in the array. Is it possible to do so.
-
2Why not simply have an array (or vector) as a constructor parameter?Yuushi– Yuushi2012-10-23 03:37:39 +00:00Commented Oct 23, 2012 at 3:37
-
What compiler and version are you using? This is possible in two ways with C++11. Either variadic templates, or initializer lists.Benjamin Lindley– Benjamin Lindley2012-10-23 03:38:10 +00:00Commented Oct 23, 2012 at 3:38
-
For an array as the parameter, liveworkspace.org/code/7823999f46ff0a4fa45674f695b3f9ab. A vector or something would be better if you have C++11.Qaz– Qaz2012-10-23 03:38:12 +00:00Commented Oct 23, 2012 at 3:38
-
Possible dupe: stackoverflow.com/questions/6179812Dan– Dan2012-10-23 03:39:07 +00:00Commented Oct 23, 2012 at 3:39
-
I compile on ideone which uses C++ (gcc-4.3.4).illumiNatISt– illumiNatISt2012-10-23 03:42:14 +00:00Commented Oct 23, 2012 at 3:42
|
Show 1 more comment