質問するログイン新規登録

質問編集履歴

1

修正案追記

2019/10/31 11:02

投稿

Weapon
Weapon

スコア106

title CHANGED
File without changes
body CHANGED
@@ -93,4 +93,44 @@
93
93
 
94
94
  ### 補足情報
95
95
  Windows10 Pro
96
- VisualStudio2019 Community
96
+ VisualStudio2019 Community
97
+
98
+ ### P.S. 解決方法
99
+ ```C++
100
+ AllocSample::AllocSample(LPCWSTR arg_1, LPCWSTR arg_2) :str_1(nullptr), str_2(nullptr)
101
+ {
102
+ if (arg_1 != nullptr) {
103
+ int length = lstrlenW(arg_1) + 1;
104
+ str_1 = new wchar_t[length];
105
+
106
+ for (int i = 0; i < length; i++) {
107
+ str_1[i] = arg_1[i];
108
+ }
109
+ }
110
+
111
+ if (arg_2 != nullptr) {
112
+ int length2 = lstrlenW(arg_2) + 1;
113
+ str_2 = new wchar_t[length2];
114
+
115
+ for (int i = 0; i < length2; i++) {
116
+ str_2[i] = arg_2[i];
117
+ }
118
+ }
119
+ };
120
+
121
+ AllocSample::AllocSample(const::AllocSample& obj) :str_1(nullptr), str_2(nullptr)
122
+ {
123
+ int length = lstrlenW(obj.str_1) + 1;
124
+ this->str_1 = new wchar_t[length];
125
+ for (int i = 0; i < length; i++) {
126
+ str_1[i] = obj.str_1[i];
127
+ }
128
+
129
+ int length2 = lstrlenW(obj.str_2) + 1;
130
+ this->str_2 = new wchar_t[length2];
131
+ for (int i = 0; i < length2; i++) {
132
+ str_2[i] = obj.str_2[i];
133
+ }
134
+ };
135
+ ```
136
+ Constructor, Copy Constructorを以上のように修正しました.