質問編集履歴

6

文章を編集しました。

2020/09/30 06:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,18 +1,6 @@
1
- Game.hpp内でSprite.hppをインルードすると提示画像ようなエードが出るですが恐らく前方宣言によるもの思われるのですがこれはどうすればいいのでしょうか?前方宣言ついは調べしたわかません
1
+ 提示コードのDrawVertexクラス部のンストラクタ部引数 Owner->VertexAttribute構造体を指して VertexAttribute a いう引数を作りたいのですがどうすればいいのでしょうか?色々試してもエラーなっうので原因たです
2
2
 
3
- 自分の勘ではSprite.hppにGame.hppがあるためのと思われますがどうすればいいのでしょうか?
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
- ![イメージ説明](50b67a4cfef15451b0837639c6374455.png)
3
+ ![イメージ説明](f952dd71ffdd47952107e68f78499b0d.png)
14
-
15
-
16
4
 
17
5
  ```hpp
18
6
 
@@ -20,21 +8,7 @@
20
8
 
21
9
  #define ___GAME_H
22
10
 
23
-
24
-
25
11
  #include <iostream>
26
-
27
- #include <vector>
28
-
29
-
30
-
31
- #include "Sprite.hpp"
32
-
33
-
34
-
35
-
36
-
37
-
38
12
 
39
13
  class Game
40
14
 
@@ -42,202 +16,100 @@
42
16
 
43
17
  public:
44
18
 
19
+ struct VertexAttribute
45
20
 
21
+ {
46
22
 
47
- struct VertexAttribute
48
-
49
- {
50
-
51
-
52
-
53
- float Position[3];
23
+ float Position[3];
54
-
55
- };
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
- Game();
66
-
67
-
68
-
69
- void draw();
70
-
71
-
72
-
73
- std::vector<Game::VertexAttribute> vert;
74
-
75
-
76
-
77
- //Sprite *sp;
78
-
79
-
80
-
81
-
82
24
 
83
25
  };
84
26
 
27
+ Game();
85
28
 
29
+ void draw();
30
+
31
+ };
86
32
 
87
33
  #endif;
88
34
 
89
35
  ```
90
36
 
91
-
92
-
93
37
  ```cpp
94
38
 
95
39
  #include "Game.hpp"
96
-
97
-
98
-
99
-
100
40
 
101
41
  Game::Game()
102
42
 
103
43
  {
104
44
 
105
- /*
106
-
107
- vert.push_back(VertexAttribute{ 1,1,0 });
108
-
109
- vert.push_back(VertexAttribute{ 2,2,0 });
110
-
111
- vert.push_back(VertexAttribute{ 3,3,0 });
112
-
113
-
114
-
115
- sp = new Sprite(this, vert);
116
-
117
-
118
-
119
- */
120
-
121
45
  }
122
-
123
-
124
46
 
125
47
  void Game::draw()
126
48
 
127
49
  {
128
50
 
129
- printf("Draw\n");
51
+ printf("Draw\n");
130
52
 
131
53
  }
132
54
 
133
-
134
-
135
55
  ```
136
-
137
-
138
-
139
-
140
-
141
-
142
56
 
143
57
  ```hpp
144
58
 
145
- #ifndef ___SPRITE_
59
+ #ifndef ___DRAW_VERTEX_
146
60
 
147
- #define ___SPRITE_
61
+ #define ___DRAW_VERTEX_
148
62
 
149
-
150
-
151
- #include <vector>
63
+ #include <iostream>
152
64
 
153
65
  #include "Game.hpp"
154
66
 
155
-
156
-
157
- class Sprite
67
+ class DrawVertex
158
68
 
159
69
  {
160
70
 
161
71
  public:
162
72
 
73
+ DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100]);//コンストラクタ
163
74
 
75
+ void Draw();//描画する
164
76
 
165
- //コンストラクタ
77
+ private:
166
78
 
167
- Sprite(Game* Owner, std::vector<Game::VertexAttribute> a);
79
+ GLuint vao;
168
80
 
169
-
81
+ GLuint vbo;
170
82
 
171
-
83
+ GLuint ibo;
172
84
 
173
- std::vector<Game::VertexAttribute> vert;
85
+ float *vertex;
86
+
87
+ float* index;
174
88
 
175
89
  };
176
-
177
-
178
90
 
179
91
  #endif
180
92
 
181
93
  ```
182
94
 
183
-
184
-
185
95
  ```cpp
186
96
 
187
- #include "Sprite.hpp"
97
+ #include "DrawVertex.hpp"
188
98
 
189
-
99
+ //#include "Game.hpp"
190
-
191
-
192
100
 
193
101
  //コンストラクタ
194
102
 
195
- Sprite::Sprite(class Game* Owner, std::vector<Game::VertexAttribute> a)
103
+ DrawVertex::DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100])
196
104
 
197
105
  {
198
106
 
199
- Owner->draw();
107
+ };
200
108
 
109
+ void DrawVertex::Draw()
201
110
 
202
-
111
+ {
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
112
 
211
113
  }
212
114
 
213
-
214
-
215
-
216
-
217
115
  ```
218
-
219
- ```cpp
220
-
221
- #include <iostream>
222
-
223
- #include "Game.hpp"
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
- int main()
232
-
233
- {
234
-
235
-
236
-
237
- return 0;
238
-
239
- }
240
-
241
-
242
-
243
- ```

5

タイトルと文章を編集しました。

2020/09/30 06:09

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- クラスAスBを作りクラスB中でクラスAのポインタを引数に取る引数リストを作りたい。依存性の注入
1
+ 依存性注入というアプローチ前方宣言と思われる構文エ解決方法が知りたい。
test CHANGED
@@ -1,18 +1,16 @@
1
- 提示コードのDrawVertexクラス部のコストラタ部の引数でぜ識別子エラーになってしまうのでしょうか? Game* Onwerというコードの部分ですがどうすればいいのでしょうか?
1
+ Game.hpp内でSprite.hppをインクルードると提示画像ようなエラーコードが出るのですが恐らく前方宣言によるものと思われるのですがこれはどうすればいいのでしょうか?前方宣言については調べましたがわかりません。
2
-
3
-
4
-
2
+
5
- Githubコードを提示コード再現ました。
3
+ 自分の勘ではSprite.hppにGame.hppがあるためと思われますがどうすればいいのでしょうか?
6
-
7
-
8
-
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
9
- ![イメージ説明](f952dd71ffdd47952107e68f78499b0d.png)
13
+ ![イメージ説明](50b67a4cfef15451b0837639c6374455.png)
10
-
11
-
12
-
13
-
14
-
15
- Github: https://github.com/Shigurechan/OpenGL
16
14
 
17
15
 
18
16
 
@@ -26,6 +24,18 @@
26
24
 
27
25
  #include <iostream>
28
26
 
27
+ #include <vector>
28
+
29
+
30
+
31
+ #include "Sprite.hpp"
32
+
33
+
34
+
35
+
36
+
37
+
38
+
29
39
  class Game
30
40
 
31
41
  {
@@ -46,6 +56,12 @@
46
56
 
47
57
 
48
58
 
59
+
60
+
61
+
62
+
63
+
64
+
49
65
  Game();
50
66
 
51
67
 
@@ -54,14 +70,22 @@
54
70
 
55
71
 
56
72
 
73
+ std::vector<Game::VertexAttribute> vert;
74
+
75
+
76
+
77
+ //Sprite *sp;
78
+
79
+
80
+
81
+
82
+
57
83
  };
58
84
 
59
85
 
60
86
 
61
87
  #endif;
62
88
 
63
-
64
-
65
89
  ```
66
90
 
67
91
 
@@ -78,7 +102,21 @@
78
102
 
79
103
  {
80
104
 
81
-
105
+ /*
106
+
107
+ vert.push_back(VertexAttribute{ 1,1,0 });
108
+
109
+ vert.push_back(VertexAttribute{ 2,2,0 });
110
+
111
+ vert.push_back(VertexAttribute{ 3,3,0 });
112
+
113
+
114
+
115
+ sp = new Sprite(this, vert);
116
+
117
+
118
+
119
+ */
82
120
 
83
121
  }
84
122
 
@@ -92,17 +130,93 @@
92
130
 
93
131
  }
94
132
 
133
+
134
+
95
- ```
135
+ ```
136
+
137
+
138
+
139
+
96
140
 
97
141
 
98
142
 
99
143
  ```hpp
100
144
 
101
- #ifndef ___DRAW_VERTEX_
145
+ #ifndef ___SPRITE_
102
-
146
+
103
- #define ___DRAW_VERTEX_
147
+ #define ___SPRITE_
148
+
149
+
150
+
104
-
151
+ #include <vector>
152
+
105
-
153
+ #include "Game.hpp"
154
+
155
+
156
+
157
+ class Sprite
158
+
159
+ {
160
+
161
+ public:
162
+
163
+
164
+
165
+ //コンストラクタ
166
+
167
+ Sprite(Game* Owner, std::vector<Game::VertexAttribute> a);
168
+
169
+
170
+
171
+
172
+
173
+ std::vector<Game::VertexAttribute> vert;
174
+
175
+ };
176
+
177
+
178
+
179
+ #endif
180
+
181
+ ```
182
+
183
+
184
+
185
+ ```cpp
186
+
187
+ #include "Sprite.hpp"
188
+
189
+
190
+
191
+
192
+
193
+ //コンストラクタ
194
+
195
+ Sprite::Sprite(class Game* Owner, std::vector<Game::VertexAttribute> a)
196
+
197
+ {
198
+
199
+ Owner->draw();
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ }
212
+
213
+
214
+
215
+
216
+
217
+ ```
218
+
219
+ ```cpp
106
220
 
107
221
  #include <iostream>
108
222
 
@@ -110,94 +224,20 @@
110
224
 
111
225
 
112
226
 
227
+
228
+
229
+
230
+
113
- class DrawVertex
231
+ int main()
114
-
232
+
115
- {
233
+ {
116
-
117
- public:
234
+
118
-
119
-
120
-
121
- DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100]);//コンストラクタ
235
+
122
-
123
-
124
-
125
- void Draw();//描画する
236
+
126
-
127
-
128
-
129
- private:
130
-
131
-
132
-
133
- GLuint vao;
237
+ return 0;
134
-
135
- GLuint vbo;
238
+
136
-
137
- GLuint ibo;
138
-
139
-
140
-
141
- float *vertex;
142
-
143
- float* index;
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
- };
239
+ }
152
-
153
-
154
-
155
- #endif
240
+
156
-
157
-
158
-
241
+
242
+
159
- ```
243
+ ```
160
-
161
-
162
-
163
-
164
-
165
- ```cpp
166
-
167
- #include "DrawVertex.hpp"
168
-
169
- //#include "Game.hpp"
170
-
171
-
172
-
173
-
174
-
175
- //コンストラクタ
176
-
177
- DrawVertex::DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100])
178
-
179
- {
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
- };
190
-
191
-
192
-
193
-
194
-
195
- void DrawVertex::Draw()
196
-
197
- {
198
-
199
-
200
-
201
- }
202
-
203
- ```

4

文章を編集しました。

2020/09/29 12:48

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,12 +2,20 @@
2
2
 
3
3
 
4
4
 
5
+ Githubのコードを提示コードで再現しました。
6
+
7
+
8
+
5
9
  ![イメージ説明](f952dd71ffdd47952107e68f78499b0d.png)
6
10
 
7
11
 
8
12
 
9
13
 
10
14
 
15
+ Github: https://github.com/Shigurechan/OpenGL
16
+
17
+
18
+
11
19
  ```hpp
12
20
 
13
21
  #ifndef ___GAME_H

3

タイトルと文章を編集しました。

2020/09/29 11:26

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- クラスAの中でクラスBを作りクラスBの中でクラスAのポインタを引数に取る引数リストを作りたい。
1
+ クラスAの中でクラスBを作りクラスBの中でクラスAのポインタを引数に取る引数リストを作りたい。依存性の注入
test CHANGED
@@ -1,4 +1,4 @@
1
- 提示コードのDrawVertexクラス部のコンストラクタ部の引数 Owner->VertexAttribute構造体を指して VertexAttribute a という引数を作りたいのですがどうすればいいのでしょうか?色々試してもエラーになってしまうので原因が知りたです。
1
+ 提示コードのDrawVertexクラス部のコンストラクタ部の引数ですがなぜ識別子エラーになってしまうのでしょうか? Game* Onwerというコード部分ですがどうすればいいのでしょうか?
2
2
 
3
3
 
4
4
 

2

文章を編集しました

2020/09/29 06:33

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- クラスAの中でクラスBを作りクラスBの中でクラスAの構造体型使う方法が知りたい。
1
+ クラスAの中でクラスBを作りクラスBの中でクラスAのポインタ引数に取る引数リストを作りたい。
test CHANGED
File without changes

1

提示コードと文章を修正しました。

2020/09/29 06:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,22 +1,22 @@
1
- 提示コードのspriteクラス部の/////ントのOwner->VertexAttribute構造体を指して VertexAttribute a という引数を作りたいのですがどうすればいいのでしょうか?色々試してもエラーになってしまうので原因が知りたです。
1
+ 提示コードのDrawVertexクラス部のコンラクタ部引数 Owner->VertexAttribute構造体を指して VertexAttribute a という引数を作りたいのですがどうすればいいのでしょうか?色々試してもエラーになってしまうので原因が知りたです。
2
+
3
+
4
+
5
+ ![イメージ説明](f952dd71ffdd47952107e68f78499b0d.png)
2
6
 
3
7
 
4
8
 
5
9
 
6
10
 
11
+ ```hpp
12
+
13
+ #ifndef ___GAME_H
14
+
15
+ #define ___GAME_H
7
16
 
8
17
 
9
18
 
10
-
11
-
12
-
13
-
14
-
15
- ```cpp
16
-
17
19
  #include <iostream>
18
-
19
-
20
20
 
21
21
  class Game
22
22
 
@@ -26,27 +26,83 @@
26
26
 
27
27
 
28
28
 
29
- Game();
30
-
31
-
32
-
33
29
  struct VertexAttribute
34
30
 
35
31
  {
36
32
 
37
- public:
33
+
38
34
 
39
35
  float Position[3];
40
36
 
41
37
  };
42
38
 
39
+
40
+
41
+ Game();
42
+
43
+
44
+
45
+ void draw();
46
+
47
+
48
+
43
49
  };
50
+
51
+
52
+
53
+ #endif;
54
+
55
+
56
+
57
+ ```
58
+
59
+
60
+
61
+ ```cpp
62
+
63
+ #include "Game.hpp"
44
64
 
45
65
 
46
66
 
47
67
 
48
68
 
69
+ Game::Game()
70
+
71
+ {
72
+
73
+
74
+
75
+ }
76
+
77
+
78
+
79
+ void Game::draw()
80
+
81
+ {
82
+
83
+ printf("Draw\n");
84
+
85
+ }
86
+
87
+ ```
88
+
89
+
90
+
91
+ ```hpp
92
+
93
+ #ifndef ___DRAW_VERTEX_
94
+
95
+ #define ___DRAW_VERTEX_
96
+
97
+
98
+
99
+ #include <iostream>
100
+
101
+ #include "Game.hpp"
102
+
103
+
104
+
49
- class sprite
105
+ class DrawVertex
50
106
 
51
107
  {
52
108
 
@@ -54,15 +110,29 @@
54
110
 
55
111
 
56
112
 
57
- sprite(Game* Owner, Owner->VertexAttribute a)/////////////////////
113
+ DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100]);//コンストラクタ
58
-
59
- {
60
114
 
61
115
 
62
116
 
63
- }
117
+ void Draw();//描画する
64
118
 
119
+
120
+
121
+ private:
122
+
123
+
124
+
65
- };
125
+ GLuint vao;
126
+
127
+ GLuint vbo;
128
+
129
+ GLuint ibo;
130
+
131
+
132
+
133
+ float *vertex;
134
+
135
+ float* index;
66
136
 
67
137
 
68
138
 
@@ -70,11 +140,35 @@
70
140
 
71
141
 
72
142
 
143
+ };
144
+
145
+
146
+
73
- int main()
147
+ #endif
148
+
149
+
150
+
151
+ ```
152
+
153
+
154
+
155
+
156
+
157
+ ```cpp
158
+
159
+ #include "DrawVertex.hpp"
160
+
161
+ //#include "Game.hpp"
162
+
163
+
164
+
165
+
166
+
167
+ //コンストラクタ
168
+
169
+ DrawVertex::DrawVertex(Game* Onwer, const char* texture, Game::VertexAttribute vert[100], int idx[100])
74
170
 
75
171
  {
76
-
77
-
78
172
 
79
173
 
80
174
 
@@ -84,10 +178,18 @@
84
178
 
85
179
 
86
180
 
181
+ };
182
+
183
+
184
+
185
+
186
+
87
- return 0;
187
+ void DrawVertex::Draw()
188
+
189
+ {
190
+
191
+
88
192
 
89
193
  }
90
194
 
91
-
92
-
93
195
  ```