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

質問編集履歴

9

*の位置を修正したことにより変わったエラーメッセージを記載しました。

2021/10/15 05:02

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -78,15 +78,7 @@
78
78
  dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
79
79
  ^
80
80
  Interaction.cpp:65:17: error: use of undeclared identifier 'sep_force'
81
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
82
- ^
83
- Interaction.cpp:72:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
84
- return dv_sep;
81
+ 文字数の問題で省略しています。
85
- ^~~~~~
86
-
87
- ^
88
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
89
- 20 errors generated.
90
82
  ```
91
83
 
92
84
  ### 該当のソースコード

8

*の位置の修正により変わったエラーメッセージを記載しました。

2021/10/15 05:02

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -15,8 +15,23 @@
15
15
  ・コンパイル
16
16
  /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 Interaction.cpp
17
17
 
18
+ ### *の位置を修正した後のエラーメッセージ
19
+ ```
20
+ Interaction.cpp:72:10: warning: address of stack memory associated with local variable 'dv_sep' returned [-Wreturn-stack-address]
21
+ return dv_sep;
22
+ ^~~~~~
23
+ Interaction.cpp:111:10: warning: address of stack memory associated with local variable 'dv_coh' returned [-Wreturn-stack-address]
24
+ return dv_coh;
25
+ ^~~~~~
26
+ 2 warnings generated.
27
+ "/usr/bin/ld" -demangle -lto_library /opt/homebrew/Cellar/llvm/12.0.0_1/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 11.0.0 0.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out /var/folders/k_/4f4mn0653xg82mqzygyrfqlr0000gn/T/Interaction-23c16d.o -lc++ -lSystem /opt/homebrew/Cellar/llvm/12.0.0_1/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a
28
+ Undefined symbols for architecture arm64:
29
+ "_main", referenced from:
30
+ implicit entry/start for main executable
31
+ ld: symbol(s) not found for architecture arm64
32
+ clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
33
+ ```
18
34
  ### 発生している問題・エラーメッセージ
19
-
20
35
  ```
21
36
  Interaction.cpp:41:22: error: use of undeclared identifier 'n'
22
37
  for(int j = 0; j < n; j++) {
@@ -68,21 +83,8 @@
68
83
  Interaction.cpp:72:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
69
84
  return dv_sep;
70
85
  ^~~~~~
71
- Interaction.cpp:88:11: error: use of undeclared identifier 'E_dis'
86
+
72
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
73
- ^
74
- Interaction.cpp:89:13: error: use of undeclared identifier 'E_angle'
75
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
76
- ^
77
- Interaction.cpp:90:15: error: use of undeclared identifier 'coh_dis'
78
- if(dis >= coh_dis){
79
- ^
80
- Interaction.cpp:103:17: error: use of undeclared identifier 'coh_force'
81
- dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
82
87
  ^
83
- Interaction.cpp:104:17: error: use of undeclared identifier 'coh_force'
84
- dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
85
- ^
86
88
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
87
89
  20 errors generated.
88
90
  ```
@@ -284,5 +286,4 @@
284
286
 
285
287
  return withNum;
286
288
  }
287
-
288
289
  ```

7

解決できる部分は解決して訂正しました

2021/10/15 05:00

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
@@ -1,1 +1,1 @@
1
- オブジェクト指向についての勉強が浅くなぜエラーが出ているのか分かりません
1
+ オブジェクト指向についての勉強が浅くなぜ未定義エラーが出ているのか分かりません
body CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  C++でのエラーについて
4
4
  コンストラクタを設定しているはずなのに変数やメソッドのエラーが出ます。
5
- オブジェクト指向についての勉強が浅くなぜエラーが出ているのか分かりません
5
+ オブジェクト指向についての勉強が浅くなぜコンストラクタでセットしている部分の未定義エラーが出ているのか分かりません
6
6
  教えていただけると助かります。
7
7
 
8
8
  ### 実行環境
@@ -18,84 +18,73 @@
18
18
  ### 発生している問題・エラーメッセージ
19
19
 
20
20
  ```
21
- Interaction.cpp:10:6: warning: comparison of array 'this->dis' not equal to a null pointer is always true [-Wtautological-pointer-compare]
22
- if(dis != NULL) delete [] dis;
23
- ^~~ ~~~~
24
- Interaction.cpp:10:19: error: cannot delete expression of type 'double [36]'
25
- if(dis != NULL) delete [] dis;
26
- ^ ~~~
27
- Interaction.cpp:11:6: warning: comparison of array 'this->angle' not equal to a null pointer is always true [-Wtautological-pointer-compare]
28
- if(angle != NULL) delete [] angle;
29
- ^~~~~ ~~~~
30
- Interaction.cpp:11:21: error: cannot delete expression of type 'double [36]'
31
- if(angle != NULL) delete [] angle;
32
- ^ ~~~~~
33
- Interaction.cpp:39:22: error: use of undeclared identifier 'n'
21
+ Interaction.cpp:41:22: error: use of undeclared identifier 'n'
34
22
  for(int j = 0; j < n; j++) {
35
23
  ^
36
- Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
37
- if(is_seated) continue; // 着席した人は力の影響を受けない
38
- ^~~~~~~~~
39
- is_seat
40
- Interaction.cpp:25:110: note: 'is_seat' declared here
41
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
42
- ^
43
- Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
24
+ Interaction.cpp:46:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
44
25
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
45
26
  ^~~
46
27
  div
47
28
  /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
48
29
  inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
49
30
  ^
50
- Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
31
+ Interaction.cpp:46:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
51
32
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
52
33
  ^~~
53
- Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
34
+ Interaction.cpp:46:14: error: use of undeclared identifier 'E_dis'
54
35
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
55
36
  ^
56
- Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
37
+ Interaction.cpp:47:5: error: use of undeclared identifier 'angle'
57
38
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
58
39
  ^
59
- Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
40
+ Interaction.cpp:47:16: error: use of undeclared identifier 'E_angle'
60
41
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
61
42
  ^
62
- Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
43
+ Interaction.cpp:50:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
63
44
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
64
45
  ^~~
65
46
  div
66
47
  /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
67
48
  inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
68
49
  ^
69
- Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
50
+ Interaction.cpp:50:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
70
51
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
71
52
  ^~~
72
- Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
53
+ Interaction.cpp:50:18: error: use of undeclared identifier 'sep_dis'
73
54
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
74
55
  ^
75
- Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
56
+ Interaction.cpp:50:29: error: use of undeclared identifier 'angle'
76
57
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
77
58
  ^
78
- Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
59
+ Interaction.cpp:50:41: error: use of undeclared identifier 'sep_angle'
79
60
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
80
61
  ^
81
- Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
62
+ Interaction.cpp:64:17: error: use of undeclared identifier 'sep_force'
82
63
  dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
83
64
  ^
84
- Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
65
+ Interaction.cpp:65:17: error: use of undeclared identifier 'sep_force'
85
66
  dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
86
67
  ^
87
- Interaction.cpp:70:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
68
+ Interaction.cpp:72:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
88
69
  return dv_sep;
89
70
  ^~~~~~
90
- Interaction.cpp:86:11: error: use of undeclared identifier 'E_dis'
71
+ Interaction.cpp:88:11: error: use of undeclared identifier 'E_dis'
91
72
  dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
92
73
  ^
93
- Interaction.cpp:87:13: error: use of undeclared identifier 'E_angle'
74
+ Interaction.cpp:89:13: error: use of undeclared identifier 'E_angle'
94
75
  angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
95
76
  ^
77
+ Interaction.cpp:90:15: error: use of undeclared identifier 'coh_dis'
78
+ if(dis >= coh_dis){
79
+ ^
80
+ Interaction.cpp:103:17: error: use of undeclared identifier 'coh_force'
81
+ dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
82
+ ^
83
+ Interaction.cpp:104:17: error: use of undeclared identifier 'coh_force'
84
+ dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
85
+ ^
96
86
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
97
- 2 warnings and 20 errors generated.
87
+ 20 errors generated.
98
-
99
88
  ```
100
89
 
101
90
  ### 該当のソースコード
@@ -169,11 +158,13 @@
169
158
  set(nn, sf, sd, sa, cf, cd);
170
159
  }
171
160
 
161
+ /*
172
162
  //--- デストラクタ定義 ---//
173
163
  Interaction::~Interaction(){
174
164
  if(dis != NULL) delete [] dis;
175
165
  if(angle != NULL) delete [] angle;
176
166
  }
167
+ */
177
168
 
178
169
  //--- セッタ ---//
179
170
  void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
@@ -202,7 +193,7 @@
202
193
  // 個体間距離と角度の計算 //
203
194
  for(int j = 0; j < n; j++) {
204
195
  if(num == j) continue;
205
- if(is_seated) continue; // 着席した人は力の影響を受けない
196
+ if(is_seat) continue; // 着席した人は力の影響を受けない
206
197
  if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
207
198
  // 個体間距離と角度を計算 //
208
199
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
@@ -293,4 +284,5 @@
293
284
 
294
285
  return withNum;
295
286
  }
287
+
296
288
  ```

6

修正後のエラーを記載しました

2021/10/15 04:34

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -18,79 +18,84 @@
18
18
  ### 発生している問題・エラーメッセージ
19
19
 
20
20
  ```
21
- ./Interaction.cpp:4:1: error: use of undeclared identifier 'Interaction'
22
- Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
21
+ Interaction.cpp:10:6: warning: comparison of array 'this->dis' not equal to a null pointer is always true [-Wtautological-pointer-compare]
23
- ^
24
- ./Interaction.cpp:9:1: error: use of undeclared identifier 'Interaction'
25
- Interaction::~Interaction(){
22
+ if(dis != NULL) delete [] dis;
26
- ^
23
+ ^~~ ~~~~
27
- ./Interaction.cpp:15:6: error: use of undeclared identifier 'Interaction'
24
+ Interaction.cpp:10:19: error: cannot delete expression of type 'double [36]'
25
+ if(dis != NULL) delete [] dis;
26
+ ^ ~~~
28
- void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
27
+ Interaction.cpp:11:6: warning: comparison of array 'this->angle' not equal to a null pointer is always true [-Wtautological-pointer-compare]
28
+ if(angle != NULL) delete [] angle;
29
- ^
29
+ ^~~~~ ~~~~
30
- ./Interaction.cpp:25:8: error: use of undeclared identifier 'Interaction'
30
+ Interaction.cpp:11:21: error: cannot delete expression of type 'double [36]'
31
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
31
+ if(angle != NULL) delete [] angle;
32
- ^
32
+ ^ ~~~~~
33
- ./Interaction.cpp:39:22: error: use of undeclared identifier 'n'
33
+ Interaction.cpp:39:22: error: use of undeclared identifier 'n'
34
34
  for(int j = 0; j < n; j++) {
35
35
  ^
36
- ./Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
36
+ Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
37
37
  if(is_seated) continue; // 着席した人は力の影響を受けない
38
38
  ^~~~~~~~~
39
39
  is_seat
40
- ./Interaction.cpp:25:110: note: 'is_seat' declared here
40
+ Interaction.cpp:25:110: note: 'is_seat' declared here
41
41
  double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
42
42
  ^
43
- ./Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
43
+ Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
44
44
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
45
45
  ^~~
46
46
  div
47
47
  /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
48
48
  inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
49
49
  ^
50
- In file included from classroomExit1.cpp:12:
51
- ./Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
50
+ Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
52
51
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
53
52
  ^~~
54
- ./Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
53
+ Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
55
54
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
56
55
  ^
57
- ./Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
56
+ Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
58
57
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
59
58
  ^
60
- ./Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
59
+ Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
61
60
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
62
61
  ^
63
- ./Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
62
+ Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
64
63
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
65
64
  ^~~
66
65
  div
67
66
  /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
68
67
  inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
69
68
  ^
70
- In file included from classroomExit1.cpp:12:
71
- ./Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
69
+ Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
72
70
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
73
71
  ^~~
74
- ./Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
72
+ Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
75
73
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
76
74
  ^
77
- ./Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
75
+ Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
78
76
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
79
77
  ^
80
- ./Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
78
+ Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
81
79
  if(dis[j] <= sep_dis && angle[j] <= sep_angle){
82
80
  ^
83
- ./Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
81
+ Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
84
82
  dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
85
83
  ^
86
- ./Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
84
+ Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
87
85
  dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
88
86
  ^
89
- ./Interaction.cpp:70:10: error: cannot initialize return object of type 'double' with an lvalue of type 'double [2]'
87
+ Interaction.cpp:70:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
90
88
  return dv_sep;
91
89
  ^~~~~~
90
+ Interaction.cpp:86:11: error: use of undeclared identifier 'E_dis'
91
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
92
+ ^
93
+ Interaction.cpp:87:13: error: use of undeclared identifier 'E_angle'
94
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
95
+ ^
92
96
  fatal error: too many errors emitted, stopping now [-ferror-limit=]
93
- 20 errors generated.
97
+ 2 warnings and 20 errors generated.
98
+
94
99
  ```
95
100
 
96
101
  ### 該当のソースコード

5

ファイル、ifdef -> ifndefを修正しました。#include <cmath>を追加しました。

2021/10/15 03:59

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -96,9 +96,10 @@
96
96
  ### 該当のソースコード
97
97
 
98
98
  ```C++
99
- #Interaction.hpp
99
+ /* Interaction.hpp */
100
- #ifdef __CLASS__INTERACTION
100
+ #ifndef __CLASS__INTERACTION
101
101
 
102
+ #include <cmath>
102
103
  #include <vector>
103
104
 
104
105
  #define __CLASS__INTERACTION
@@ -155,6 +156,7 @@
155
156
  #endif
156
157
  ```
157
158
  ```C++
159
+ /* Interaction.cpp */
158
160
  #include "Interaction.hpp"
159
161
 
160
162
  //--- コンストラクタ定義 ---//

4

実行環境を記載しました

2021/10/15 03:18

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -14,8 +14,6 @@
14
14
 
15
15
  ・コンパイル
16
16
  /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 Interaction.cpp
17
- グラフの描画をするために色々使っています。
18
- このクラスを作る以前は問題なくコンパイルできていました。
19
17
 
20
18
  ### 発生している問題・エラーメッセージ
21
19
 

3

コンパイルのコマンドを記載しました

2021/10/15 02:55

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -13,7 +13,7 @@
13
13
  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
14
14
 
15
15
  ・コンパイル
16
- /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 classroomExit1.cpp -L/opt/homebrew/opt/llvm/lib -stdlib=libc++ -I/opt/homebrew/Cellar/freeglut/3.2.1_1/include/ -L/opt/homebrew/Cellar/freeglut/3.2.1_1/lib/ -I/opt/homebrew/opt/ -I/opt/homebrew/Cellar/eigen/3.3.9/include `pkg-config --cflags --libs opencv4` -framework OpenGL -lglut -lm
16
+ /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 Interaction.cpp
17
17
  グラフの描画をするために色々使っています。
18
18
  このクラスを作る以前は問題なくコンパイルできていました。
19
19
 

2

実行環境を記載しました

2021/10/14 16:47

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -5,6 +5,18 @@
5
5
  オブジェクト指向についての勉強が浅くなぜエラーが出ているのか分かりません
6
6
  教えていただけると助かります。
7
7
 
8
+ ### 実行環境
9
+ ・C++バージョン
10
+ Apple clang version 12.0.5 (clang-1205.0.22.9)
11
+ Target: arm64-apple-darwin20.3.0
12
+ Thread model: posix
13
+ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
14
+
15
+ ・コンパイル
16
+ /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 classroomExit1.cpp -L/opt/homebrew/opt/llvm/lib -stdlib=libc++ -I/opt/homebrew/Cellar/freeglut/3.2.1_1/include/ -L/opt/homebrew/Cellar/freeglut/3.2.1_1/lib/ -I/opt/homebrew/opt/ -I/opt/homebrew/Cellar/eigen/3.3.9/include `pkg-config --cflags --libs opencv4` -framework OpenGL -lglut -lm
17
+ グラフの描画をするために色々使っています。
18
+ このクラスを作る以前は問題なくコンパイルできていました。
19
+
8
20
  ### 発生している問題・エラーメッセージ
9
21
 
10
22
  ```

1

エラーメッセージを原文まま載せました

2021/10/14 16:20

投稿

jagaimo0
jagaimo0

スコア33

title CHANGED
File without changes
body CHANGED
@@ -8,8 +8,79 @@
8
8
  ### 発生している問題・エラーメッセージ
9
9
 
10
10
  ```
11
+ ./Interaction.cpp:4:1: error: use of undeclared identifier 'Interaction'
12
+ Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
13
+ ^
14
+ ./Interaction.cpp:9:1: error: use of undeclared identifier 'Interaction'
15
+ Interaction::~Interaction(){
16
+ ^
17
+ ./Interaction.cpp:15:6: error: use of undeclared identifier 'Interaction'
18
+ void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
19
+ ^
20
+ ./Interaction.cpp:25:8: error: use of undeclared identifier 'Interaction'
21
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
22
+ ^
23
+ ./Interaction.cpp:39:22: error: use of undeclared identifier 'n'
24
+ for(int j = 0; j < n; j++) {
25
+ ^
26
+ ./Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
27
+ if(is_seated) continue; // 着席した人は力の影響を受けない
28
+ ^~~~~~~~~
29
+ is_seat
30
+ ./Interaction.cpp:25:110: note: 'is_seat' declared here
31
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
32
+ ^
33
+ ./Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
34
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
35
+ ^~~
36
+ div
37
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
38
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
39
+ ^
40
+ In file included from classroomExit1.cpp:12:
41
+ ./Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
42
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
43
+ ^~~
44
+ ./Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
45
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
46
+ ^
47
+ ./Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
48
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
49
+ ^
50
+ ./Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
51
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
52
+ ^
53
+ ./Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
54
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
55
+ ^~~
56
+ div
57
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
58
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
59
+ ^
60
+ In file included from classroomExit1.cpp:12:
61
+ ./Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
62
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
63
+ ^~~
11
- use of undeclared identifier 'sep_dis'
64
+ ./Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
65
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
66
+ ^
67
+ ./Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
68
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
69
+ ^
70
+ ./Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
71
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
72
+ ^
73
+ ./Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
74
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
75
+ ^
76
+ ./Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
77
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
78
+ ^
79
+ ./Interaction.cpp:70:10: error: cannot initialize return object of type 'double' with an lvalue of type 'double [2]'
80
+ return dv_sep;
81
+ ^~~~~~
82
+ fatal error: too many errors emitted, stopping now [-ferror-limit=]
12
- など全ての変数やメソッドについて未定義のエラーメッセージが出ます
83
+ 20 errors generated.
13
84
  ```
14
85
 
15
86
  ### 該当のソースコード