Skip to content

cpp_initalize

Player(int i, int j);

目标: 5 player, ith player -> (i, 2*i)

// array of class
// C++ >= 17
Player p[5];
for (int i = 0; i < 5; i++) {
    p[i](i, 2*i);
}
// C++ < 17
...
https://stackoverflow.com/questions/49114168/initialize-static-array-of-objects-c

// array of class pointer
Player* p = new Player[5];
for (int i = 0; i < 5; i++) {
    arr[i] = Player(i, 2*i);
}

https://stackoverflow.com/questions/33137464/how-to-initialize-static-member-array-with-a-result-of-a-function

Comments