feat(cmat): Completed Ex61 Part 1
This commit is contained in:
+3
-9
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ using std::string;
|
|||||||
using std::exception;
|
using std::exception;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::vector<Person *> people;
|
std::vector<std::shared_ptr<Person>> people;
|
||||||
|
|
||||||
string namePrompt = "Enter name: ";
|
string namePrompt = "Enter name: ";
|
||||||
string name;
|
string name;
|
||||||
@@ -38,7 +39,7 @@ int main() {
|
|||||||
throw PersonException("invalid age");
|
throw PersonException("invalid age");
|
||||||
}
|
}
|
||||||
|
|
||||||
Person *personPtr = new Person(name, age);
|
auto personPtr = std::make_shared<Person>(name, age);
|
||||||
|
|
||||||
cout << salaryPrompt;
|
cout << salaryPrompt;
|
||||||
cin >> salary;
|
cin >> salary;
|
||||||
@@ -64,12 +65,5 @@ int main() {
|
|||||||
cin >> name;
|
cin >> name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete all the person(s) in the vector
|
|
||||||
for (std::vector<Person *>::iterator iter = people.begin(); iter != people.end(); ++iter) {
|
|
||||||
delete *iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "There are " << Person::GetCount() << " Person(s) left dangling\n";
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user