Skip to content

Commit 02dacaf

Browse files
committed
Refactor pointer to impl
1 parent 6090fc7 commit 02dacaf

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

PointerToImpl/main.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
/**
22
* @file main.cpp
33
* @author Xuhua Huang
4-
* @brief
4+
* @brief
55
* @version 0.1
66
* @date 2023-03-25
7-
*
7+
*
88
* g++ .\main.cpp -o ./piml.exe -std=c++2a
99
* ./pimpl.exe
10-
*
10+
*
1111
* @copyright ueg (c) 2023
12-
*
12+
*
1313
*/
1414

1515
#include "person.hpp"
1616

17-
int main() {
17+
int main()
18+
{
1819
pimpl::Person p("Alice", 30);
19-
std::cout << p.name() << ", " << p.age() << std::endl;
20+
std::cout << p.name() << ", " << p.age() << "\n";
2021

2122
p.setName("Bob");
2223
p.setAge(40);
23-
std::cout << p.name() << ", " << p.age() << std::endl;
24+
std::cout << p.name() << ", " << p.age() << "\n";
2425

2526
return 0;
2627
}

PointerToImpl/person.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Person
2828
std::string name() const;
2929
void setName(const std::string& name);
3030

31+
/**
32+
* @brief Set the Name object
33+
* The setName function is a member of the pimpl::Person class and takes an rvalue reference to a std::string as its
34+
* parameter, allowing the caller to set the name of the Person object by moving the string.
35+
*/
36+
void setName(std::string&&);
37+
3138
int age() const;
3239
void setAge(int age);
3340

0 commit comments

Comments
 (0)