A class that owns data does not automatically need hand-written cleanup. Strings and vectors already manage their own storage. If your class contains these members directly, their destructors run automatically when the enclosing object is destroyed.
The rule of zero is a design guideline: prefer classes that do not define custom destructors, copy constructors, copy assignments, move constructors, or move assignments. Compose them from members that already manage their resources correctly. Ordinary constructors and useful application operations are still welcome; “zero” refers to those special resource-management functions, not to every member function.
The compiler's generated memberwise behavior then follows the members' behavior. A class containing a string and a vector can be copied as an independent value. A class containing a unique pointer will not be copyable by default, because that member forbids copying. The rule of zero does not promise every class can be copied; it helps keep ownership consistent with the types you chose.
#include <iostream>
#include <vector>
struct Readings {
std::vector<int> values;
};
int main() {
Readings original{{4, 6}};
Readings revised = original;
revised.values.push_back(8);
std::cout << original.values.size() << ' ' << revised.values.size() << '\n';
}
The example prints 2 3. The vector member supplies both independent copying and automatic cleanup. This explains why the notebook copy in the previous section needed no custom copying code either. Your Plan uses the same approach with a string and a vector. The copy is already made in main; append the new stop inside addStop(). The unchanged original count and label let you check that adding a stop did not disturb the copied data.
addStop() using the vector's push_back. The revised plan must have 2 stops, the original must retain 1, and the copied label must remain Saturday.Edit main.cpp, then press Run to inspect the Console. Press Submit to check your work. Keep the supplied probes in place.