質問編集履歴

3

コード編集

2016/12/18 00:14

投稿

aidida
aidida

スコア14

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,11 @@
46
46
 
47
47
 
48
48
 
49
+ ```c++
50
+
49
- ```Sample.h
51
+ **Sample.h**
52
+
53
+
50
54
 
51
55
  #ifndef _SAMPLE_H_
52
56
 
@@ -82,7 +86,11 @@
82
86
 
83
87
 
84
88
 
89
+ ```c++
90
+
85
- ```Sample.cpp
91
+ **Sample.cpp**
92
+
93
+
86
94
 
87
95
  #include "Sample.h"
88
96
 
@@ -120,7 +128,11 @@
120
128
 
121
129
 
122
130
 
131
+ ```c++
132
+
123
- ```main.cpp
133
+ **main.cpp**
134
+
135
+
124
136
 
125
137
  #include "Sample.h"
126
138
 

2

コード編集

2016/12/18 00:14

投稿

aidida
aidida

スコア14

test CHANGED
File without changes
test CHANGED
@@ -46,13 +46,7 @@
46
46
 
47
47
 
48
48
 
49
- ```C++
50
-
51
-
52
-
53
- **Sample.h**
49
+ ```Sample.h
54
-
55
-
56
50
 
57
51
  #ifndef _SAMPLE_H_
58
52
 
@@ -84,13 +78,11 @@
84
78
 
85
79
  #endif // _SAMPLE_H_
86
80
 
81
+ ```
87
82
 
88
83
 
89
84
 
90
-
91
- **Sample.cpp**
85
+ ```Sample.cpp
92
-
93
-
94
86
 
95
87
  #include "Sample.h"
96
88
 
@@ -124,11 +116,11 @@
124
116
 
125
117
  }
126
118
 
119
+ ```
127
120
 
128
121
 
129
- **main.cpp**
130
122
 
131
-
123
+ ```main.cpp
132
124
 
133
125
  #include "Sample.h"
134
126
 
@@ -154,6 +146,4 @@
154
146
 
155
147
  }
156
148
 
157
- コード
158
-
159
149
  ```

1

コード追加

2016/12/18 00:12

投稿

aidida
aidida

スコア14

test CHANGED
File without changes
test CHANGED
@@ -43,3 +43,117 @@
43
43
 
44
44
 
45
45
  よろしくお願いしますー
46
+
47
+
48
+
49
+ ```C++
50
+
51
+
52
+
53
+ **Sample.h**
54
+
55
+
56
+
57
+ #ifndef _SAMPLE_H_
58
+
59
+ #define _SAMPLE_H_
60
+
61
+
62
+
63
+ class Sample{
64
+
65
+ public:
66
+
67
+ int a; // publicなメンバ変数
68
+
69
+ private:
70
+
71
+ int b; // privateなメンバ変数
72
+
73
+ public:
74
+
75
+ void func1();
76
+
77
+ private:
78
+
79
+ void func2();
80
+
81
+ };
82
+
83
+
84
+
85
+ #endif // _SAMPLE_H_
86
+
87
+
88
+
89
+
90
+
91
+ **Sample.cpp**
92
+
93
+
94
+
95
+ #include "Sample.h"
96
+
97
+ #include <iostream>
98
+
99
+
100
+
101
+ using namespace std;
102
+
103
+
104
+
105
+ void Sample::func1(){
106
+
107
+ cout << "func1" << endl;
108
+
109
+ a = 1;
110
+
111
+ b = 1;
112
+
113
+ func2(); // func2ないから、func1を呼び出す
114
+
115
+ }
116
+
117
+ void Sample::func2(){
118
+
119
+ a = 2;
120
+
121
+ b = 2;
122
+
123
+ cout << "a=" << a << "," << "b=" << b << endl;
124
+
125
+ }
126
+
127
+
128
+
129
+ **main.cpp**
130
+
131
+
132
+
133
+ #include "Sample.h"
134
+
135
+ #include <iostream>
136
+
137
+
138
+
139
+ using namespace std;
140
+
141
+
142
+
143
+ int main(){
144
+
145
+ Sample s;//←このsがインスタンス化されてないものと思ってました
146
+
147
+ s.a = 1;
148
+
149
+ //s.b = 2;
150
+
151
+ s.func1();
152
+
153
+ //s.func2();
154
+
155
+ }
156
+
157
+ コード
158
+
159
+ ```