1

I have a code:

Array a1( 1,2,3,4,-1), a2(1,3,5,7,11,-1);

How to make Array constructor when I know that in the end is always -1, amount of numbers before -1 is unknown and class Array has only one constructor?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
Marcinho
  • 77
  • 1
  • 3
  • 1
    Check this link [va_arg](http://www.cplusplus.com/reference/cstdarg/va_arg/) – Shubham Nov 19 '13 at 14:59
  • Consider using variatic templates (on C++11). Or you can develop syntax like this Array a = 1, 2, 3, 4; (overload "=" operator and ","). This is not very safe, but funny syntax. – Denis Gladkiy Nov 19 '13 at 15:55
  • @DenisGladkiy, It works for assignment (and that's how Boost.Assign works), but not for initialization (that would just initialize it to 4). Both can be replaced with initializer lists in C++11. – chris Nov 19 '13 at 16:40

0 Answers0