回答編集履歴
5
ファイル名の入れ忘れ修正
answer
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
ヘッダーに実装も書きこんで下さい。
|
3
3
|
|
4
4
|
```c++
|
5
|
+
// Hearder.hpp
|
5
6
|
#pragma once
|
6
7
|
|
7
8
|
#include <iostream>
|
4
クラスの特殊化よりメソッドの特殊化のほうが適していそうなので修正
answer
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
ヘッダーに実装も書きこんで下さい。
|
3
3
|
|
4
4
|
```c++
|
5
|
-
// Hearder.hpp
|
6
5
|
#pragma once
|
7
6
|
|
8
7
|
#include <iostream>
|
@@ -35,19 +34,14 @@
|
|
35
34
|
}
|
36
35
|
};
|
37
36
|
|
38
|
-
template<>
|
39
|
-
|
37
|
+
template<> Sample<std::vector<int>>::Sample(const std::vector<int> a)
|
40
38
|
{
|
41
|
-
explicit Sample(const std::vector<int>& a)
|
42
|
-
{
|
43
|
-
|
39
|
+
std::cout << "子クラスのSample<std::vector<int>>のコンストラクタ" << std::endl;
|
44
|
-
|
40
|
+
}
|
45
|
-
|
41
|
+
|
46
|
-
|
42
|
+
template<> void Sample<std::vector<int>>::f(){
|
47
|
-
{
|
48
|
-
|
43
|
+
std::cout << "Sample<std::vector<int>>クラスでオーバーライドしたfメソッド" << std::endl;
|
49
|
-
|
44
|
+
}
|
50
|
-
};
|
51
45
|
```
|
52
46
|
```c++
|
53
47
|
// main.cpp
|
@@ -67,7 +61,7 @@
|
|
67
61
|
return 0;
|
68
62
|
}
|
69
63
|
```
|
70
|
-
[wandboxで実行](https://wandbox.org/permlink/
|
64
|
+
[wandboxで実行](https://wandbox.org/permlink/Lqqp705K29x8hdfY)
|
71
65
|
|
72
66
|
ちなみにc++17を使える環境なら
|
73
67
|
if constexprで特殊化の所を書かずにコードを簡略化可能です。
|
3
typo修正3
answer
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
|
32
32
|
void f()override
|
33
33
|
{
|
34
|
-
std::cout << "Sample<type>クラスでオーバー
|
34
|
+
std::cout << "Sample<type>クラスでオーバーライドしたfメソッド" << std::endl;
|
35
35
|
}
|
36
36
|
};
|
37
37
|
|
@@ -105,10 +105,10 @@
|
|
105
105
|
void f()override
|
106
106
|
{
|
107
107
|
if constexpr(std::is_same_v<std::vector<int>, Type>)
|
108
|
-
std::cout << "Sample<std::vector<int>>クラスでオーバー
|
108
|
+
std::cout << "Sample<std::vector<int>>クラスでオーバーライドしたfメソッド" << std::endl;
|
109
109
|
else std::cout << "Sample<type>クラスでオーバーライドしたfメソッド" << std::endl;
|
110
110
|
}
|
111
111
|
};
|
112
112
|
```
|
113
113
|
|
114
|
-
[wandboxで実行](https://wandbox.org/permlink/
|
114
|
+
[wandboxで実行](https://wandbox.org/permlink/mj9XzYIO7erRrMc4)
|
2
誤記修正2
answer
CHANGED
@@ -36,9 +36,8 @@
|
|
36
36
|
};
|
37
37
|
|
38
38
|
template<>
|
39
|
-
|
39
|
+
struct Sample<std::vector<int>>:public Test
|
40
40
|
{
|
41
|
-
public:
|
42
41
|
explicit Sample(const std::vector<int>& a)
|
43
42
|
{
|
44
43
|
std::cout << "子クラスのSample<std::vector<int>>のコンストラクタ" << std::endl;
|
@@ -68,7 +67,7 @@
|
|
68
67
|
return 0;
|
69
68
|
}
|
70
69
|
```
|
71
|
-
[wandboxで実行](https://wandbox.org/permlink/
|
70
|
+
[wandboxで実行](https://wandbox.org/permlink/if3GYMe6Masqyvyc)
|
72
71
|
|
73
72
|
ちなみにc++17を使える環境なら
|
74
73
|
if constexprで特殊化の所を書かずにコードを簡略化可能です。
|
1
typo修正
answer
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
void f()override
|
48
48
|
{
|
49
|
-
std::cout << "Sample<std::vector<int>>クラスでオーバー
|
49
|
+
std::cout << "Sample<std::vector<int>>クラスでオーバーライドしたfメソッド" << std::endl;
|
50
50
|
}
|
51
51
|
};
|
52
52
|
```
|
@@ -68,7 +68,7 @@
|
|
68
68
|
return 0;
|
69
69
|
}
|
70
70
|
```
|
71
|
-
[wandboxで実行](https://wandbox.org/permlink/
|
71
|
+
[wandboxで実行](https://wandbox.org/permlink/mNy3CPP0YbyQKKIj)
|
72
72
|
|
73
73
|
ちなみにc++17を使える環境なら
|
74
74
|
if constexprで特殊化の所を書かずにコードを簡略化可能です。
|
@@ -107,9 +107,9 @@
|
|
107
107
|
{
|
108
108
|
if constexpr(std::is_same_v<std::vector<int>, Type>)
|
109
109
|
std::cout << "Sample<std::vector<int>>クラスでオーバーロードしたfメソッド" << std::endl;
|
110
|
-
else std::cout << "Sample<type>クラスでオーバー
|
110
|
+
else std::cout << "Sample<type>クラスでオーバーライドしたfメソッド" << std::endl;
|
111
111
|
}
|
112
112
|
};
|
113
113
|
```
|
114
114
|
|
115
|
-
[wandboxで実行](https://wandbox.org/permlink/
|
115
|
+
[wandboxで実行](https://wandbox.org/permlink/5Sz27iA6xopnX0uU)
|