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:

  1. c++98 standard

  2. 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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -