File tree 1 file changed +17
-2
lines changed 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,25 @@ class Formatter {
20
20
vsnprintf (_msg, MSG_LEN, fmt, args);
21
21
va_end (args);
22
22
}
23
- ~Formatter () {
23
+ Formatter (const Formatter &f) : _msg(new char [MSG_LEN]) { strcpy (_msg, f._msg ); }
24
+ Formatter (Formatter &&f) : _msg(f._msg) { f._msg = nullptr ; }
25
+ Formatter& operator =(const Formatter &f) {
26
+ // copy assign
27
+ if (this == &f) return *this ;
24
28
delete[] _msg;
25
- _msg = nullptr ;
29
+ _msg = new char [MSG_LEN];
30
+ strcpy (_msg, f._msg );
31
+ return *this ;
26
32
}
33
+ Formatter& operator =(Formatter &&f) {
34
+ // move assign
35
+ if (this == &f) return *this ;
36
+ delete[] _msg;
37
+ _msg = f._msg ;
38
+ f._msg = nullptr ;
39
+ return *this ;
40
+ }
41
+ virtual ~Formatter () { delete[] _msg; _msg = nullptr ; }
27
42
const char * msg () const noexcept { return _msg; }
28
43
};
29
44
You can’t perform that action at this time.
0 commit comments