c++ - How to initialize const size array in constructor without explicitly stating the size in class declaration? -
i need like
class foo { foo(); int a[]; }
further in cpp-file:
foo::foo() : a{1,2,3,4} {}
peculiarities:
c++98 standard
array not int, initializing list longer. though values known @ compile time, can change time time
edit: option suitable, when new[]
used memory allocation, but, again, undesirable state array size explicitly:
class foo { foo(); int * a; }
further in cpp-file:
foo::foo() { = new[]; // impossible // filling array values }
you cannot that: size of array part of type of array, , hence of class. constructor part of class. class needs exist first before can call constructors, constructor call cannot influence class definition.
Comments
Post a Comment