質問編集履歴
3
コード編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,7 +22,9 @@
|
|
22
22
|
|
23
23
|
よろしくお願いしますー
|
24
24
|
|
25
|
+
```c++
|
25
|
-
|
26
|
+
**Sample.h**
|
27
|
+
|
26
28
|
#ifndef _SAMPLE_H_
|
27
29
|
#define _SAMPLE_H_
|
28
30
|
|
@@ -40,7 +42,9 @@
|
|
40
42
|
#endif // _SAMPLE_H_
|
41
43
|
```
|
42
44
|
|
45
|
+
```c++
|
43
|
-
|
46
|
+
**Sample.cpp**
|
47
|
+
|
44
48
|
#include "Sample.h"
|
45
49
|
#include <iostream>
|
46
50
|
|
@@ -59,7 +63,9 @@
|
|
59
63
|
}
|
60
64
|
```
|
61
65
|
|
66
|
+
```c++
|
62
|
-
|
67
|
+
**main.cpp**
|
68
|
+
|
63
69
|
#include "Sample.h"
|
64
70
|
#include <iostream>
|
65
71
|
|
2
コード編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,10 +22,7 @@
|
|
22
22
|
|
23
23
|
よろしくお願いしますー
|
24
24
|
|
25
|
-
```C++
|
26
|
-
|
27
|
-
|
25
|
+
```Sample.h
|
28
|
-
|
29
26
|
#ifndef _SAMPLE_H_
|
30
27
|
#define _SAMPLE_H_
|
31
28
|
|
@@ -41,10 +38,9 @@
|
|
41
38
|
};
|
42
39
|
|
43
40
|
#endif // _SAMPLE_H_
|
41
|
+
```
|
44
42
|
|
45
|
-
|
46
|
-
|
43
|
+
```Sample.cpp
|
47
|
-
|
48
44
|
#include "Sample.h"
|
49
45
|
#include <iostream>
|
50
46
|
|
@@ -61,9 +57,9 @@
|
|
61
57
|
b = 2;
|
62
58
|
cout << "a=" << a << "," << "b=" << b << endl;
|
63
59
|
}
|
60
|
+
```
|
64
61
|
|
65
|
-
|
62
|
+
```main.cpp
|
66
|
-
|
67
63
|
#include "Sample.h"
|
68
64
|
#include <iostream>
|
69
65
|
|
@@ -76,5 +72,4 @@
|
|
76
72
|
s.func1();
|
77
73
|
//s.func2();
|
78
74
|
}
|
79
|
-
コード
|
80
75
|
```
|
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,4 +20,61 @@
|
|
20
20
|
C++が初心者なので、他言語との違いを含めてアドバイスください。
|
21
21
|
大規模開発にカプセル化が必要だということですか?
|
22
22
|
|
23
|
-
よろしくお願いしますー
|
23
|
+
よろしくお願いしますー
|
24
|
+
|
25
|
+
```C++
|
26
|
+
|
27
|
+
**Sample.h**
|
28
|
+
|
29
|
+
#ifndef _SAMPLE_H_
|
30
|
+
#define _SAMPLE_H_
|
31
|
+
|
32
|
+
class Sample{
|
33
|
+
public:
|
34
|
+
int a; // publicなメンバ変数
|
35
|
+
private:
|
36
|
+
int b; // privateなメンバ変数
|
37
|
+
public:
|
38
|
+
void func1();
|
39
|
+
private:
|
40
|
+
void func2();
|
41
|
+
};
|
42
|
+
|
43
|
+
#endif // _SAMPLE_H_
|
44
|
+
|
45
|
+
|
46
|
+
**Sample.cpp**
|
47
|
+
|
48
|
+
#include "Sample.h"
|
49
|
+
#include <iostream>
|
50
|
+
|
51
|
+
using namespace std;
|
52
|
+
|
53
|
+
void Sample::func1(){
|
54
|
+
cout << "func1" << endl;
|
55
|
+
a = 1;
|
56
|
+
b = 1;
|
57
|
+
func2(); // func2ないから、func1を呼び出す
|
58
|
+
}
|
59
|
+
void Sample::func2(){
|
60
|
+
a = 2;
|
61
|
+
b = 2;
|
62
|
+
cout << "a=" << a << "," << "b=" << b << endl;
|
63
|
+
}
|
64
|
+
|
65
|
+
**main.cpp**
|
66
|
+
|
67
|
+
#include "Sample.h"
|
68
|
+
#include <iostream>
|
69
|
+
|
70
|
+
using namespace std;
|
71
|
+
|
72
|
+
int main(){
|
73
|
+
Sample s;//←このsがインスタンス化されてないものと思ってました
|
74
|
+
s.a = 1;
|
75
|
+
//s.b = 2;
|
76
|
+
s.func1();
|
77
|
+
//s.func2();
|
78
|
+
}
|
79
|
+
コード
|
80
|
+
```
|