There is such a class:

class Foo { public: int bar; Foo(int b) { bar = b; } }; 

and here it is:

 template<class T> class Bax { private: T *data; public: Bax() { data = new T[4]; } }; 

How to rewrite 2nd grade to make it work

 Bax<Foo> bax; Bax<int> bax2; 

everything turned out to be much simpler .. just need to allocate memory not through new, but through malloc

  • The fact of the matter is that I need to write my vector - Roma Tulin
  • one
    So apparently you will not. Create an array of T ** data pointers. In general, look at the implementation of a thread of a standard container, the stl code is open. - alphard

1 answer 1

Regular funds do not. You can try new overload for the Bax class, which would call the constructor with a parameter. But you can change the first class by adding a default constructor.

  class Foo { public: int bar; Foo(int b) { bar = b; } Foo():bar(0){} // << --- добавить }; 

Look here, they give a couple of specific tips http://www.gamedev.ru/code/forum/?id=75910

  • four
    The easiest way to do this is: Foo (int b = 0) {bar = b; } - IAZ
  • Well, bar to make the list initialization. - AlexDenisov