Answers for "make a vector of an objects c++"

0

make a vector of an objects c++

#include <vector>
using std::vector;

class MyClass { .... };

vector<MyClass> myVector( 100, MyClass() );
/* myVector now contains 100 objects of type MyClass, built with the default constructor */

vector<MyClass> myVector2;
// MyVector2 is empty

myVector2.assign( 100, MyClass() );

// My Vector2 now contains 100 objects of type MyClass, built with default ctor
Posted by: Guest on October-13-2020

Code answers related to "make a vector of an objects c++"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language