How to create a dynamic array of class in C++ -
i know how create class array dynamically, tried doing
class a{ public: int a; int b; } main(){ *temp; temp[somevalue] = new (temp) }
but issue dont want limit array somevalue want extend it, thought of using std::vector
, std::lis
t stuck in implementation
simple example of std::vector
:
class myclass { public: int a; int b; myclass(int a, int b) : a(a), b(b) { } }; std::vector<myclass> temp; temp.push_back(myclass(1, 2)); temp.push_back(myclass(3, 4)); // temp vector contains 2 items
Comments
Post a Comment