Skip to content

Commit a0fea7b

Browse files
committed
improved ch07
1 parent c638184 commit a0fea7b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

ch07/ex7_05.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
class Person {
1515
std::string name;
1616
std::string address;
17-
18-
std::string getName() const { return name; }
19-
std::string getAddress() const { return address; }
17+
public:
18+
const std::string& getName() const { return name; }
19+
const std::string& getAddress() const { return address; }
2020
};
2121

2222
#endif

ch07/ex7_09.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
#include <iostream>
1414

1515
struct Person {
16-
std::string getName() const { return name; }
17-
std::string getAddress() const { return address; }
18-
16+
const std::string& getName() const { return name; }
17+
const std::string& getAddress() const { return address; }
18+
1919
std::string name;
2020
std::string address;
2121
};
2222

2323
std::istream &read(std::istream &is, Person &person)
2424
{
2525
is >> person.name >> person.address;
26+
if (!is) person = Person();
2627
return is;
2728
}
2829

0 commit comments

Comments
 (0)