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

質問編集履歴

3

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

2020/10/16 04:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,62 +1,9 @@
1
- Player::Player()ンストラクタ///のコードですが依存性の注入で外部のGame::BulletData構造体のインスタンスのアドレス変数に入れる方法がわかりません。
1
+ 下記のードの////コメント内部のコードですが外部のクラス内の構造体のインスタンスを配列のポインタに入れる方法はどうすればいいのでしょうか?型名ありませんや不完全な型など様々エラーが発生してしまいどうすればいいかわかりません。Player::Player();コンストラクタの
2
+ for文のコードはどうすればいいのでしょうか?
2
3
 
3
4
 
4
-
5
+ ![イメージ説明](e7a891452262e2470b6cab42f88b8e0a.png)
5
6
  ```cpp
6
-
7
- class Game
8
- {
9
- public:
10
-
11
- Game(); //コンストラクタ
12
- bool Initialization(); //初期化
13
- bool RunLoop(); //メインループ
14
- void Update(); //計算
15
- void GenerateOutput(); //描画
16
-
17
- bool mIsRunLoop; //メインループ
18
- void KeyInput(); //キー入力
19
-
20
-
21
-
22
- //頂点属性
23
- struct VertexAttribute {
24
-
25
- GLfloat Position[3]; //頂点座標
26
- GLfloat uv[2]; //UV座標
27
-
28
- };
29
-
30
-
31
-
32
- //----------------------------------------------------------------描画オブジェクト
33
-
34
- //キューブ
35
- std::vector<Game::VertexAttribute> vertex; //頂点
36
- std::vector<unsigned int> vertex_index; //インデックス
37
-
38
- //地面
39
- std::vector<Game::VertexAttribute> Ground; //頂点
40
- std::vector<unsigned int> Ground_index; //インデックス
41
-
42
-
43
-
44
-
45
-
46
- //----------------------------------------------------------------描画オブジェクト
47
-
48
- struct BulletData////////////////////////////////////////////////////////////////
49
- {
50
- bool frag;
51
-
52
- glm::ivec2 pos; //弾の座標
53
- glm::ivec2 vec; //弾の飛んでいく向き
54
-
55
- };
56
- };
57
- ```
58
-
59
- ```cpp
60
7
  #ifndef ___PLAYER_HPP_
61
8
  #define ___PLAYER_HPP_
62
9
 
@@ -88,7 +35,7 @@
88
35
 
89
36
 
90
37
 
91
- class Game;
38
+ //class Game;
92
39
  class Player
93
40
  {
94
41
  public:
@@ -102,10 +49,10 @@
102
49
  private:
103
50
  Game* mOwner;
104
51
 
105
- //struct BulletData_* mBullet[10];
52
+ //////////////////////////////////
106
- mOwner->BulletData* mBullet[10];
53
+ struct BulletData* mBullet[10];
54
+ ///////////////////////////////////////////////
107
55
 
108
-
109
56
  bool mIsAttack = false;
110
57
 
111
58
 
@@ -130,18 +77,20 @@
130
77
  #include "Player.hpp"
131
78
  #include "Game.hpp"
132
79
 
133
-
134
80
  Player::Player(Game* g)
135
81
  {
136
82
  mOwner = g;
137
-
83
+ ////////////////////////////////////////////////////////////////////////////
138
84
  for (int i = 0; i < 10; i++)
139
85
  {
86
+ mBullet[i] = mOwner->BulletData{ false,glm::ivec2(0,0),glm::ivec2(0,0) };
87
+
140
- ////
88
+ // mBullet[i] = struct BulletData_{ false, glm::ivec2(0, 0), glm::ivec2(0, 0) };
89
+
141
90
  }
91
+ /////////////////////////////////////////////////////////////////////////////
142
92
 
143
93
 
144
-
145
94
  //up
146
95
  mSprite[0][0] = new Sprite(mOwner, "Assets/Player.png", glm::ivec2(0, 0), glm::ivec2(CELL, CELL));
147
96
  mSprite[0][1] = new Sprite(mOwner, "Assets/Player.png", glm::ivec2(CELL * 1, 0), glm::ivec2(CELL, CELL));
@@ -163,4 +112,174 @@
163
112
 
164
113
  }
165
114
 
115
+
116
+
117
+ void Player::Update()
118
+ {
119
+
120
+ }
121
+
122
+ void Player::Draw()
123
+ {
124
+
125
+ }
126
+
127
+
128
+
129
+
130
+
131
+
132
+ Player::~Player()
133
+ {
134
+
135
+ }
136
+
137
+ ```
138
+
139
+ ```cpp
140
+ #ifndef ___GMAE_H_
141
+ #define ___GMAE_H_
142
+
143
+ #define CELL 48
144
+
145
+ //画面サイズを指定
146
+ #define WIDTH (16 * 70)
147
+ #define HEIGHT (9 * 70)
148
+ #define PI (3.14159265359f) //円周率
149
+
150
+
151
+ #define STAGE_HEIGHT 16
152
+ #define STAGE_WIDTH 23
153
+
154
+
155
+ //自作ヘッダー 関係
156
+ #include "Camera.hpp"
157
+ #include "Font.hpp"
158
+ #include "Sprite.hpp"
159
+
160
+
161
+ //標準ヘッダー関係
162
+ #include "stdio.h"
163
+ #include <fstream>
164
+ #include <sstream>
165
+ #include <iostream>
166
+ #include <vector>
167
+
168
+ //OpenGL関係
169
+ #include "GLEW/include/GL/glew.h"
170
+ #include "gl/GL.h"
171
+ #include "GLFW/include/GLFW/glfw3.h"
172
+
173
+ //数学ライブラリ
174
+ #include "glm/ext.hpp"
175
+ #include <glm/ext/vector_int2.hpp>
176
+ //文字描画 ライブラリ
177
+ #include <ft2build.h>
178
+ //#include FT_FREETYPE_H
179
+
180
+
181
+
182
+ //前方宣言
183
+ class Mesh;
184
+ class Sprite;
185
+ class Font;
186
+
187
+ class Game
188
+ {
189
+ public:
190
+
191
+ Game(); //コンストラクタ
192
+ bool Initialization(); //初期化
193
+ bool RunLoop(); //メインループ
194
+ void Update(); //計算
195
+ void GenerateOutput(); //描画
196
+
197
+ bool mIsRunLoop; //メインループ
198
+ void KeyInput(); //キー入力
199
+
200
+
201
+
202
+ //頂点属性
203
+ struct VertexAttribute {
204
+
205
+ GLfloat Position[3]; //頂点座標
206
+ GLfloat uv[2]; //UV座標
207
+
208
+ };
209
+
210
+
211
+
212
+ //----------------------------------------------------------------描画オブジェクト
213
+
214
+ //キューブ
215
+ std::vector<Game::VertexAttribute> vertex; //頂点
216
+ std::vector<unsigned int> vertex_index; //インデックス
217
+
218
+ //地面
219
+ std::vector<Game::VertexAttribute> Ground; //頂点
220
+ std::vector<unsigned int> Ground_index; //インデックス
221
+
222
+
223
+
224
+
225
+
226
+ //----------------------------------------------------------------描画オブジェクト
227
+ //////////////////////////////////////////
228
+ struct BulletData
229
+ {
230
+ bool frag;
231
+
232
+ glm::ivec2 pos; //弾の座標
233
+ glm::ivec2 vec; //弾の飛んでいく向き
234
+
235
+ };
236
+ ////////////////////////////////////////
237
+
238
+ Sprite* gBullet[4];
239
+
240
+ enum class eKeyInput
241
+ {
242
+ Up,
243
+ Down,
244
+ Left,
245
+ Right,
246
+ Invalid,
247
+ };
248
+
249
+
250
+ //マップ
251
+ Sprite* Map[100];
252
+
253
+
254
+
255
+ int stage[STAGE_HEIGHT][STAGE_WIDTH] =
256
+ {
257
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
258
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
259
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
260
+ {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
261
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
262
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
263
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
264
+ {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
265
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
266
+ {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
267
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
268
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
269
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
270
+
271
+
272
+
273
+ };
274
+
275
+
276
+
277
+
278
+
279
+ Font* font;
280
+
281
+
282
+ ...関係ないので省略
283
+
284
+ };
166
285
  ```

2

質問内容を編集しました。

2020/10/16 04:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,15 +1,93 @@
1
- ///のコードですが依存性の注入で外部の構造体のインスタンスのアドレスを変数に入れる方法がわかりません。このコンパイルエラーはどうやって解決するのでしょうか?
1
+ Player::Player()コンストラクタ///のコードですが依存性の注入で外部のGame::BulletData構造体のインスタンスのアドレスを変数に入れる方法がわかりません。
2
2
 
3
- エラーコード
4
- ![イメージ説明](e73b44cd3d0e71fa6dee944f1a498b9c.png)
5
3
 
6
4
 
5
+ ```cpp
7
6
 
7
+ class Game
8
+ {
9
+ public:
10
+
11
+ Game(); //コンストラクタ
12
+ bool Initialization(); //初期化
13
+ bool RunLoop(); //メインループ
14
+ void Update(); //計算
15
+ void GenerateOutput(); //描画
8
16
 
17
+ bool mIsRunLoop; //メインループ
18
+ void KeyInput(); //キー入力
9
19
 
20
+
21
+
22
+ //頂点属性
23
+ struct VertexAttribute {
24
+
25
+ GLfloat Position[3]; //頂点座標
26
+ GLfloat uv[2]; //UV座標
27
+
28
+ };
29
+
30
+
31
+
32
+ //----------------------------------------------------------------描画オブジェクト
33
+
34
+ //キューブ
35
+ std::vector<Game::VertexAttribute> vertex; //頂点
36
+ std::vector<unsigned int> vertex_index; //インデックス
37
+
38
+ //地面
39
+ std::vector<Game::VertexAttribute> Ground; //頂点
40
+ std::vector<unsigned int> Ground_index; //インデックス
41
+
42
+
43
+
44
+
45
+
46
+ //----------------------------------------------------------------描画オブジェクト
47
+
48
+ struct BulletData////////////////////////////////////////////////////////////////
49
+ {
50
+ bool frag;
51
+
52
+ glm::ivec2 pos; //弾の座標
53
+ glm::ivec2 vec; //弾の飛んでいく向き
54
+
55
+ };
56
+ };
57
+ ```
58
+
10
59
  ```cpp
60
+ #ifndef ___PLAYER_HPP_
61
+ #define ___PLAYER_HPP_
11
62
 
63
+ //自作ヘッダー類
64
+ #include "Sprite.hpp"
65
+ #include "Game.hpp"
12
66
 
67
+ //標準ヘッダー関係
68
+ #include "stdio.h"
69
+ #include <fstream>
70
+ #include <sstream>
71
+ #include <iostream>
72
+ #include <vector>
73
+
74
+ //OpenGL関係
75
+ #include "GLEW/include/GL/glew.h"
76
+ #include "gl/GL.h"
77
+ #include "GLFW/include/GLFW/glfw3.h"
78
+
79
+ //数学ライブラリ
80
+ #include "glm/ext.hpp"
81
+ #include <glm/ext/vector_int2.hpp>
82
+ //文字描画 ライブラリ
83
+ #include <ft2build.h>
84
+
85
+ //#include FT_FREETYPE_H
86
+
87
+
88
+
89
+
90
+
13
91
  class Game;
14
92
  class Player
15
93
  {
@@ -25,7 +103,7 @@
25
103
  Game* mOwner;
26
104
 
27
105
  //struct BulletData_* mBullet[10];
28
- struct mOwner->BulletData_* mBullet[10];
106
+ mOwner->BulletData* mBullet[10];
29
107
 
30
108
 
31
109
  bool mIsAttack = false;
@@ -45,9 +123,12 @@
45
123
  };
46
124
 
47
125
  #endif
126
+
48
127
  ```
49
128
 
50
129
  ```cpp
130
+ #include "Player.hpp"
131
+ #include "Game.hpp"
51
132
 
52
133
 
53
134
  Player::Player(Game* g)
@@ -56,7 +137,7 @@
56
137
 
57
138
  for (int i = 0; i < 10; i++)
58
139
  {
59
- mBullet[i] = new mOwner->struct BulletData_{false,glm::ivec2(0,0),glm::ivec2(0,0) };//////////
140
+ ////
60
141
  }
61
142
 
62
143
 
@@ -82,5 +163,4 @@
82
163
 
83
164
  }
84
165
 
85
-
86
166
  ```

1

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

2020/10/16 03:27

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,55 @@
1
1
  ///のコードですが依存性の注入で外部の構造体のインスタンスのアドレスを変数に入れる方法がわかりません。このコンパイルエラーはどうやって解決するのでしょうか?
2
2
 
3
+ エラーコード
4
+ ![イメージ説明](e73b44cd3d0e71fa6dee944f1a498b9c.png)
3
5
 
6
+
7
+
8
+
9
+
4
10
  ```cpp
5
11
 
6
12
 
13
+ class Game;
14
+ class Player
15
+ {
16
+ public:
17
+
18
+ Player(Game* g);
19
+ ~Player();
20
+
21
+ void Update();
22
+ void Draw();
23
+
24
+ private:
25
+ Game* mOwner;
26
+
27
+ //struct BulletData_* mBullet[10];
28
+ struct mOwner->BulletData_* mBullet[10];
29
+
30
+
31
+ bool mIsAttack = false;
32
+
33
+
34
+
35
+ //プレイヤー
36
+ enum eKeyInput key; //プレイヤーのキー入力
37
+
38
+ Sprite* mSprite[4][2];
39
+ glm::ivec2 mPosition; //座標
40
+ glm::ivec2 mVector; //向き
41
+
42
+
43
+
44
+ int mAnim = 0; //アニメーション管理
45
+ };
46
+
47
+ #endif
48
+ ```
49
+
50
+ ```cpp
51
+
52
+
7
53
  Player::Player(Game* g)
8
54
  {
9
55
  mOwner = g;