// B doesn't have a default constructor.
class A {
public:
A(Important resource) : b(resource) {}
B b;
};
Reading about rule of three to figure out an issue with copying instances of a class into a vector.
So the issue is that we're generating instances inside a loop:
std::vector<A> some_vector(0);
for (int i = 0; i < 7; i++)
some_vector.push_back(A(resources[i]));
From what we see with Valgrind, it smells like the copy constructor is mucking things up. When we change the code to:
std::vector<A*> some_vector(0);
for (int i = 0; i < 7; i++)
some_vector.push_back(new A(resources[i]));
The the issue is alleviated. Don't like doing that though when it is not needed. So I'm thinking, how would the copy constructor know what to do when it is attempting to copy a class without a proper default constructor right?