c++ - Use constructor from a class in another one to allocate an array with new -
i don't know (if it's possible) how allocate array class has constructor parameters using constructor parameters. example (i'll write what's relevant. uhm, doubt template is, still):
template <typename t> class c1 { t *array; public: c1 (int n) { array = new t [n]; }; }; class c2 { int length; int lengtharrayc1; c1<t> *array; public: c2 (int x, int y) { length = x; lengtharrayc1 = y; array = //and here's i'm lost }; }; i tried writing in many ways:
array = new [length] c1<t> (lengtharrayc1); but none worked.
can't it: object array initialization without default constructor
a type must have no-argument constructor in order new[] array of it. but, see tip in answer question using std::vector, allows specify prototype object use initializing array elements.
Comments
Post a Comment