0

I have the following code:

#include <iostream>
#include <vector>

class Test
{
public:
    int first;
    int second;

    Test(int a, int b)
    {
        first = a;
        second = b;
    }
};

int main(int argc, char* argv[])
{
    std::vector<Test> mydata({ Test(4, 8), Test(5, 3), Test(12, 7), Test(8, 9) });

    for (auto const&y : mydata)
    {
        std::cout << y.first << " / " << y.second << std::endl;
    }

    //need to free vector here or sth?

    return 0;
}

I use class constructor to initialize vector. Is the code above good or can cause errors? Should I free the vector at the end of the program?

Dave
  • 153
  • 2
  • 11

0 Answers0