I'm attempting to allocate memory for each entry of the array and initialize the members part1 and part2 to 0.
#include <iostream>
using namespace std;
class Two {
public:
int part1;
int part2;
};
int main() {
Two * dp[10]; //array of 10 pointers to objects of class Two
part1 = 0;
part2 = 0;
for (int i = 0; i < 10; i++) {
dp[i] = 0;
}
return 0;
}
Any help is appreciated. I'm new to c++ and I'm trying to understand the basic concepts. Thank you in advance!
std::vectorinstead of this array?newthings, how todeletethings. A thorough, solid knowledge and understanding of the fundamentals of how objects are managed in dynamic scope is a required skill for every C++ developer. Only once there is good understanding of how to correctly implement arrays, and manual linked list, then you get to move on tostd::vector,std::list, et. al., and use your newly-acquired knowledge to write logically correct code.