質問編集履歴

9

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

2021/10/15 05:02

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -158,420 +158,404 @@
158
158
 
159
159
  Interaction.cpp:65:17: error: use of undeclared identifier 'sep_force'
160
160
 
161
+ 文字数の問題で省略しています。
162
+
163
+ ```
164
+
165
+
166
+
167
+ ### 該当のソースコード
168
+
169
+
170
+
171
+ ```C++
172
+
173
+ /* Interaction.hpp */
174
+
175
+ #ifndef __CLASS__INTERACTION
176
+
177
+
178
+
179
+ #include <cmath>
180
+
181
+ #include <vector>
182
+
183
+
184
+
185
+ #define __CLASS__INTERACTION
186
+
187
+
188
+
189
+ //===== 相互作用クラス =====//
190
+
191
+ class Interaction
192
+
193
+ {
194
+
195
+ public:
196
+
197
+ int n;
198
+
199
+ double sep_force;
200
+
201
+ double sep_dis;
202
+
203
+ double sep_angle;
204
+
205
+ double coh_force;
206
+
207
+ double coh_dis;
208
+
209
+ double dis[36] = {};
210
+
211
+ double angle[36] = {};
212
+
213
+
214
+
215
+ //--- コンストラクタ ---//
216
+
217
+ Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
218
+
219
+ ~Interaction(); // デストラクタ
220
+
221
+
222
+
223
+ //--- セッタ ---//
224
+
225
+ void set(int nn, double sf, double sd, double sa, double cf, double cd);
226
+
227
+
228
+
229
+ //--- 分離力計算 ---//
230
+
231
+ double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
232
+
233
+
234
+
235
+ //--- 結合力計算 ---//
236
+
237
+ double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
238
+
239
+
240
+
241
+ //--- 一緒にいる人数の判定 ---//
242
+
243
+ int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
244
+
245
+
246
+
247
+ //--- 距離計算 ----//
248
+
249
+ double E_dis (double xi, double xj, double yi, double yj){
250
+
251
+ double dis = 0;
252
+
253
+ dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
254
+
255
+ return dis;
256
+
257
+ }
258
+
259
+
260
+
261
+ //--- 角度計算 ---//
262
+
263
+ double E_angle (double xi, double xj, double yi, double yj){
264
+
265
+ double theta = 0;
266
+
267
+ double rx = 0; // x距離
268
+
269
+ double ry = 0; // y距離
270
+
271
+ rx = xi - xj;
272
+
273
+ ry = yi - yj;
274
+
275
+ theta = atan2(ry, rx); // 個体間角度計算
276
+
277
+
278
+
279
+ return theta;
280
+
281
+ }
282
+
283
+ };
284
+
285
+
286
+
287
+ #endif
288
+
289
+ ```
290
+
291
+ ```C++
292
+
293
+ /* Interaction.cpp */
294
+
295
+ #include "Interaction.hpp"
296
+
297
+
298
+
299
+ //--- コンストラクタ定義 ---//
300
+
301
+ Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
302
+
303
+ set(nn, sf, sd, sa, cf, cd);
304
+
305
+ }
306
+
307
+
308
+
309
+ /*
310
+
311
+ //--- デストラクタ定義 ---//
312
+
313
+ Interaction::~Interaction(){
314
+
315
+ if(dis != NULL) delete [] dis;
316
+
317
+ if(angle != NULL) delete [] angle;
318
+
319
+ }
320
+
321
+ */
322
+
323
+
324
+
325
+ //--- セッタ ---//
326
+
327
+ void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
328
+
329
+ n = nn;
330
+
331
+ sep_force = sf;
332
+
333
+ sep_dis = sd;
334
+
335
+ sep_angle = sa;
336
+
337
+ coh_force = cf;
338
+
339
+ coh_dis = cd;
340
+
341
+ }
342
+
343
+
344
+
345
+ //--- 分離力計算 ---//
346
+
347
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
348
+
349
+ double that_sum[2] = {};
350
+
351
+ double that_count = 0;
352
+
353
+ double that_ave[2] = {};
354
+
355
+ double dv_sep[2] = {};
356
+
357
+ double my_posx = posx[num];
358
+
359
+ double my_posy = posy[num];
360
+
361
+
362
+
363
+ //--- 初期化 ---//
364
+
365
+ that_sum[0] = 0;
366
+
367
+ that_sum[1] = 0;
368
+
369
+ that_count = 0;
370
+
371
+
372
+
373
+ // 個体間距離と角度の計算 //
374
+
375
+ for(int j = 0; j < n; j++) {
376
+
377
+ if(num == j) continue;
378
+
379
+ if(is_seat) continue; // 着席した人は力の影響を受けない
380
+
381
+ if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
382
+
383
+ // 個体間距離と角度を計算 //
384
+
385
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
386
+
387
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
388
+
389
+
390
+
391
+ // 分離力の範囲内なら //
392
+
393
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
394
+
395
+ // 範囲内の個体の座標を合計 //
396
+
397
+ that_sum[0] += posx[j];
398
+
399
+ that_sum[1] += posy[j];
400
+
401
+ that_count += 1;
402
+
403
+ }
404
+
405
+ }
406
+
407
+
408
+
409
+ // 範囲内の個体の平均座標 //
410
+
411
+ if(that_count != 0){
412
+
413
+ that_ave[0] = that_sum[0] / that_count;
414
+
415
+ that_ave[1] = that_sum[1] / that_count;
416
+
417
+
418
+
419
+ // 分離力 //
420
+
421
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
422
+
161
423
  dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
162
424
 
425
+ }else{
426
+
427
+ // 分離力 //
428
+
429
+ dv_sep[0] = 0;
430
+
431
+ dv_sep[1] = 0;
432
+
163
- ^
433
+ }
164
-
165
- Interaction.cpp:72:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
434
+
435
+
166
436
 
167
437
  return dv_sep;
168
438
 
169
- ^~~~~~
170
-
171
-
172
-
173
- ^
439
+ }
440
+
441
+
442
+
174
-
443
+ //--- 結合力計算 ---//
444
+
445
+ double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
446
+
447
+ double that_sum[2] = {};
448
+
449
+ double that_count = 0;
450
+
451
+ double that_ave[2] = {};
452
+
453
+ double dv_coh[2] = {};
454
+
455
+ double dis = 0;
456
+
457
+ double angle = 0;
458
+
459
+ double my_posx = posx[num];
460
+
461
+ double my_posy = posy[num];
462
+
463
+
464
+
465
+ for(int k=0; k<friends_num; k++){
466
+
467
+ if(friends[k] == -1) continue;
468
+
175
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
469
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
470
+
176
-
471
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
472
+
473
+ if(dis >= coh_dis){
474
+
475
+ that_sum[0] += posx[friends[k]];
476
+
477
+ that_sum[1] += posy[friends[k]];
478
+
479
+ that_count++;
480
+
481
+ }
482
+
483
+ }
484
+
485
+
486
+
487
+ // 範囲内の個体の平均座標 //
488
+
489
+ if(that_count != 0){
490
+
491
+ that_ave[0] = that_sum[0] / that_count;
492
+
493
+ that_ave[1] = that_sum[1] / that_count;
494
+
495
+
496
+
497
+ // 結合力 //
498
+
499
+ dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
500
+
501
+ dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
502
+
503
+ }else{
504
+
505
+ // 結合力 //
506
+
507
+ dv_coh[0] = 0;
508
+
509
+ dv_coh[1] = 0;
510
+
511
+ }
512
+
513
+
514
+
515
+ return dv_coh;
516
+
517
+ }
518
+
519
+
520
+
521
+ //--- 一緒にいる人数の判定 ---//
522
+
523
+ int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
524
+
525
+ double my_posx = posx[num];
526
+
527
+ double my_posy = posy[num];
528
+
529
+ int withNum = 0;
530
+
531
+
532
+
533
+ for(int j=0; j<n; j++) {
534
+
177
- 20 errors generated.
535
+ if(num == j) continue;
536
+
537
+ // 個体間距離と角度を計算 //
538
+
539
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
540
+
541
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
542
+
543
+ if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
544
+
545
+ for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
546
+
547
+ if(friends[k] == j) withNum++; // 合流人数
548
+
549
+ }
550
+
551
+ }
552
+
553
+ }
554
+
555
+
556
+
557
+ return withNum;
558
+
559
+ }
178
560
 
179
561
  ```
180
-
181
-
182
-
183
- ### 該当のソースコード
184
-
185
-
186
-
187
- ```C++
188
-
189
- /* Interaction.hpp */
190
-
191
- #ifndef __CLASS__INTERACTION
192
-
193
-
194
-
195
- #include <cmath>
196
-
197
- #include <vector>
198
-
199
-
200
-
201
- #define __CLASS__INTERACTION
202
-
203
-
204
-
205
- //===== 相互作用クラス =====//
206
-
207
- class Interaction
208
-
209
- {
210
-
211
- public:
212
-
213
- int n;
214
-
215
- double sep_force;
216
-
217
- double sep_dis;
218
-
219
- double sep_angle;
220
-
221
- double coh_force;
222
-
223
- double coh_dis;
224
-
225
- double dis[36] = {};
226
-
227
- double angle[36] = {};
228
-
229
-
230
-
231
- //--- コンストラクタ ---//
232
-
233
- Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
234
-
235
- ~Interaction(); // デストラクタ
236
-
237
-
238
-
239
- //--- セッタ ---//
240
-
241
- void set(int nn, double sf, double sd, double sa, double cf, double cd);
242
-
243
-
244
-
245
- //--- 分離力計算 ---//
246
-
247
- double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
248
-
249
-
250
-
251
- //--- 結合力計算 ---//
252
-
253
- double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
254
-
255
-
256
-
257
- //--- 一緒にいる人数の判定 ---//
258
-
259
- int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
260
-
261
-
262
-
263
- //--- 距離計算 ----//
264
-
265
- double E_dis (double xi, double xj, double yi, double yj){
266
-
267
- double dis = 0;
268
-
269
- dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
270
-
271
- return dis;
272
-
273
- }
274
-
275
-
276
-
277
- //--- 角度計算 ---//
278
-
279
- double E_angle (double xi, double xj, double yi, double yj){
280
-
281
- double theta = 0;
282
-
283
- double rx = 0; // x距離
284
-
285
- double ry = 0; // y距離
286
-
287
- rx = xi - xj;
288
-
289
- ry = yi - yj;
290
-
291
- theta = atan2(ry, rx); // 個体間角度計算
292
-
293
-
294
-
295
- return theta;
296
-
297
- }
298
-
299
- };
300
-
301
-
302
-
303
- #endif
304
-
305
- ```
306
-
307
- ```C++
308
-
309
- /* Interaction.cpp */
310
-
311
- #include "Interaction.hpp"
312
-
313
-
314
-
315
- //--- コンストラクタ定義 ---//
316
-
317
- Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
318
-
319
- set(nn, sf, sd, sa, cf, cd);
320
-
321
- }
322
-
323
-
324
-
325
- /*
326
-
327
- //--- デストラクタ定義 ---//
328
-
329
- Interaction::~Interaction(){
330
-
331
- if(dis != NULL) delete [] dis;
332
-
333
- if(angle != NULL) delete [] angle;
334
-
335
- }
336
-
337
- */
338
-
339
-
340
-
341
- //--- セッタ ---//
342
-
343
- void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
344
-
345
- n = nn;
346
-
347
- sep_force = sf;
348
-
349
- sep_dis = sd;
350
-
351
- sep_angle = sa;
352
-
353
- coh_force = cf;
354
-
355
- coh_dis = cd;
356
-
357
- }
358
-
359
-
360
-
361
- //--- 分離力計算 ---//
362
-
363
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
364
-
365
- double that_sum[2] = {};
366
-
367
- double that_count = 0;
368
-
369
- double that_ave[2] = {};
370
-
371
- double dv_sep[2] = {};
372
-
373
- double my_posx = posx[num];
374
-
375
- double my_posy = posy[num];
376
-
377
-
378
-
379
- //--- 初期化 ---//
380
-
381
- that_sum[0] = 0;
382
-
383
- that_sum[1] = 0;
384
-
385
- that_count = 0;
386
-
387
-
388
-
389
- // 個体間距離と角度の計算 //
390
-
391
- for(int j = 0; j < n; j++) {
392
-
393
- if(num == j) continue;
394
-
395
- if(is_seat) continue; // 着席した人は力の影響を受けない
396
-
397
- if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
398
-
399
- // 個体間距離と角度を計算 //
400
-
401
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
402
-
403
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
404
-
405
-
406
-
407
- // 分離力の範囲内なら //
408
-
409
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
410
-
411
- // 範囲内の個体の座標を合計 //
412
-
413
- that_sum[0] += posx[j];
414
-
415
- that_sum[1] += posy[j];
416
-
417
- that_count += 1;
418
-
419
- }
420
-
421
- }
422
-
423
-
424
-
425
- // 範囲内の個体の平均座標 //
426
-
427
- if(that_count != 0){
428
-
429
- that_ave[0] = that_sum[0] / that_count;
430
-
431
- that_ave[1] = that_sum[1] / that_count;
432
-
433
-
434
-
435
- // 分離力 //
436
-
437
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
438
-
439
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
440
-
441
- }else{
442
-
443
- // 分離力 //
444
-
445
- dv_sep[0] = 0;
446
-
447
- dv_sep[1] = 0;
448
-
449
- }
450
-
451
-
452
-
453
- return dv_sep;
454
-
455
- }
456
-
457
-
458
-
459
- //--- 結合力計算 ---//
460
-
461
- double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
462
-
463
- double that_sum[2] = {};
464
-
465
- double that_count = 0;
466
-
467
- double that_ave[2] = {};
468
-
469
- double dv_coh[2] = {};
470
-
471
- double dis = 0;
472
-
473
- double angle = 0;
474
-
475
- double my_posx = posx[num];
476
-
477
- double my_posy = posy[num];
478
-
479
-
480
-
481
- for(int k=0; k<friends_num; k++){
482
-
483
- if(friends[k] == -1) continue;
484
-
485
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
486
-
487
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
488
-
489
- if(dis >= coh_dis){
490
-
491
- that_sum[0] += posx[friends[k]];
492
-
493
- that_sum[1] += posy[friends[k]];
494
-
495
- that_count++;
496
-
497
- }
498
-
499
- }
500
-
501
-
502
-
503
- // 範囲内の個体の平均座標 //
504
-
505
- if(that_count != 0){
506
-
507
- that_ave[0] = that_sum[0] / that_count;
508
-
509
- that_ave[1] = that_sum[1] / that_count;
510
-
511
-
512
-
513
- // 結合力 //
514
-
515
- dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
516
-
517
- dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
518
-
519
- }else{
520
-
521
- // 結合力 //
522
-
523
- dv_coh[0] = 0;
524
-
525
- dv_coh[1] = 0;
526
-
527
- }
528
-
529
-
530
-
531
- return dv_coh;
532
-
533
- }
534
-
535
-
536
-
537
- //--- 一緒にいる人数の判定 ---//
538
-
539
- int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
540
-
541
- double my_posx = posx[num];
542
-
543
- double my_posy = posy[num];
544
-
545
- int withNum = 0;
546
-
547
-
548
-
549
- for(int j=0; j<n; j++) {
550
-
551
- if(num == j) continue;
552
-
553
- // 個体間距離と角度を計算 //
554
-
555
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
556
-
557
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
558
-
559
- if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
560
-
561
- for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
562
-
563
- if(friends[k] == j) withNum++; // 合流人数
564
-
565
- }
566
-
567
- }
568
-
569
- }
570
-
571
-
572
-
573
- return withNum;
574
-
575
- }
576
-
577
- ```

8

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

2021/10/15 05:02

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -32,10 +32,40 @@
32
32
 
33
33
 
34
34
 
35
+ ### *の位置を修正した後のエラーメッセージ
36
+
37
+ ```
38
+
39
+ Interaction.cpp:72:10: warning: address of stack memory associated with local variable 'dv_sep' returned [-Wreturn-stack-address]
40
+
41
+ return dv_sep;
42
+
43
+ ^~~~~~
44
+
45
+ Interaction.cpp:111:10: warning: address of stack memory associated with local variable 'dv_coh' returned [-Wreturn-stack-address]
46
+
47
+ return dv_coh;
48
+
49
+ ^~~~~~
50
+
51
+ 2 warnings generated.
52
+
53
+ "/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
54
+
55
+ Undefined symbols for architecture arm64:
56
+
57
+ "_main", referenced from:
58
+
59
+ implicit entry/start for main executable
60
+
61
+ ld: symbol(s) not found for architecture arm64
62
+
63
+ clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
64
+
65
+ ```
66
+
35
67
  ### 発生している問題・エラーメッセージ
36
68
 
37
-
38
-
39
69
  ```
40
70
 
41
71
  Interaction.cpp:41:22: error: use of undeclared identifier 'n'
@@ -138,438 +168,410 @@
138
168
 
139
169
  ^~~~~~
140
170
 
171
+
172
+
173
+ ^
174
+
175
+ fatal error: too many errors emitted, stopping now [-ferror-limit=]
176
+
177
+ 20 errors generated.
178
+
179
+ ```
180
+
181
+
182
+
183
+ ### 該当のソースコード
184
+
185
+
186
+
187
+ ```C++
188
+
189
+ /* Interaction.hpp */
190
+
191
+ #ifndef __CLASS__INTERACTION
192
+
193
+
194
+
195
+ #include <cmath>
196
+
197
+ #include <vector>
198
+
199
+
200
+
201
+ #define __CLASS__INTERACTION
202
+
203
+
204
+
205
+ //===== 相互作用クラス =====//
206
+
207
+ class Interaction
208
+
209
+ {
210
+
211
+ public:
212
+
213
+ int n;
214
+
215
+ double sep_force;
216
+
217
+ double sep_dis;
218
+
219
+ double sep_angle;
220
+
221
+ double coh_force;
222
+
223
+ double coh_dis;
224
+
225
+ double dis[36] = {};
226
+
227
+ double angle[36] = {};
228
+
229
+
230
+
231
+ //--- コンストラクタ ---//
232
+
141
- Interaction.cpp:88:11: error: use of undeclared identifier 'E_dis'
233
+ Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
234
+
235
+ ~Interaction(); // デストラクタ
236
+
237
+
238
+
239
+ //--- セッタ ---//
240
+
241
+ void set(int nn, double sf, double sd, double sa, double cf, double cd);
242
+
243
+
244
+
245
+ //--- 分離力計算 ---//
246
+
247
+ double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
248
+
249
+
250
+
251
+ //--- 結合力計算 ---//
252
+
253
+ double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
254
+
255
+
256
+
257
+ //--- 一緒にいる人数の判定 ---//
258
+
259
+ int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
260
+
261
+
262
+
263
+ //--- 距離計算 ----//
264
+
265
+ double E_dis (double xi, double xj, double yi, double yj){
266
+
267
+ double dis = 0;
268
+
269
+ dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
270
+
271
+ return dis;
272
+
273
+ }
274
+
275
+
276
+
277
+ //--- 角度計算 ---//
278
+
279
+ double E_angle (double xi, double xj, double yi, double yj){
280
+
281
+ double theta = 0;
282
+
283
+ double rx = 0; // x距離
284
+
285
+ double ry = 0; // y距離
286
+
287
+ rx = xi - xj;
288
+
289
+ ry = yi - yj;
290
+
291
+ theta = atan2(ry, rx); // 個体間角度計算
292
+
293
+
294
+
295
+ return theta;
296
+
297
+ }
298
+
299
+ };
300
+
301
+
302
+
303
+ #endif
304
+
305
+ ```
306
+
307
+ ```C++
308
+
309
+ /* Interaction.cpp */
310
+
311
+ #include "Interaction.hpp"
312
+
313
+
314
+
315
+ //--- コンストラクタ定義 ---//
316
+
317
+ Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
318
+
319
+ set(nn, sf, sd, sa, cf, cd);
320
+
321
+ }
322
+
323
+
324
+
325
+ /*
326
+
327
+ //--- デストラクタ定義 ---//
328
+
329
+ Interaction::~Interaction(){
330
+
331
+ if(dis != NULL) delete [] dis;
332
+
333
+ if(angle != NULL) delete [] angle;
334
+
335
+ }
336
+
337
+ */
338
+
339
+
340
+
341
+ //--- セッタ ---//
342
+
343
+ void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
344
+
345
+ n = nn;
346
+
347
+ sep_force = sf;
348
+
349
+ sep_dis = sd;
350
+
351
+ sep_angle = sa;
352
+
353
+ coh_force = cf;
354
+
355
+ coh_dis = cd;
356
+
357
+ }
358
+
359
+
360
+
361
+ //--- 分離力計算 ---//
362
+
363
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
364
+
365
+ double that_sum[2] = {};
366
+
367
+ double that_count = 0;
368
+
369
+ double that_ave[2] = {};
370
+
371
+ double dv_sep[2] = {};
372
+
373
+ double my_posx = posx[num];
374
+
375
+ double my_posy = posy[num];
376
+
377
+
378
+
379
+ //--- 初期化 ---//
380
+
381
+ that_sum[0] = 0;
382
+
383
+ that_sum[1] = 0;
384
+
385
+ that_count = 0;
386
+
387
+
388
+
389
+ // 個体間距離と角度の計算 //
390
+
391
+ for(int j = 0; j < n; j++) {
392
+
393
+ if(num == j) continue;
394
+
395
+ if(is_seat) continue; // 着席した人は力の影響を受けない
396
+
397
+ if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
398
+
399
+ // 個体間距離と角度を計算 //
400
+
401
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
402
+
403
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
404
+
405
+
406
+
407
+ // 分離力の範囲内なら //
408
+
409
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
410
+
411
+ // 範囲内の個体の座標を合計 //
412
+
413
+ that_sum[0] += posx[j];
414
+
415
+ that_sum[1] += posy[j];
416
+
417
+ that_count += 1;
418
+
419
+ }
420
+
421
+ }
422
+
423
+
424
+
425
+ // 範囲内の個体の平均座標 //
426
+
427
+ if(that_count != 0){
428
+
429
+ that_ave[0] = that_sum[0] / that_count;
430
+
431
+ that_ave[1] = that_sum[1] / that_count;
432
+
433
+
434
+
435
+ // 分離力 //
436
+
437
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
438
+
439
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
440
+
441
+ }else{
442
+
443
+ // 分離力 //
444
+
445
+ dv_sep[0] = 0;
446
+
447
+ dv_sep[1] = 0;
448
+
449
+ }
450
+
451
+
452
+
453
+ return dv_sep;
454
+
455
+ }
456
+
457
+
458
+
459
+ //--- 結合力計算 ---//
460
+
461
+ double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
462
+
463
+ double that_sum[2] = {};
464
+
465
+ double that_count = 0;
466
+
467
+ double that_ave[2] = {};
468
+
469
+ double dv_coh[2] = {};
470
+
471
+ double dis = 0;
472
+
473
+ double angle = 0;
474
+
475
+ double my_posx = posx[num];
476
+
477
+ double my_posy = posy[num];
478
+
479
+
480
+
481
+ for(int k=0; k<friends_num; k++){
482
+
483
+ if(friends[k] == -1) continue;
142
484
 
143
485
  dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
144
486
 
145
- ^
146
-
147
- Interaction.cpp:89:13: error: use of undeclared identifier 'E_angle'
148
-
149
487
  angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
150
488
 
151
- ^
152
-
153
- Interaction.cpp:90:15: error: use of undeclared identifier 'coh_dis'
154
-
155
489
  if(dis >= coh_dis){
156
490
 
491
+ that_sum[0] += posx[friends[k]];
492
+
493
+ that_sum[1] += posy[friends[k]];
494
+
495
+ that_count++;
496
+
157
- ^
497
+ }
498
+
158
-
499
+ }
500
+
501
+
502
+
503
+ // 範囲内の個体の平均座標 //
504
+
505
+ if(that_count != 0){
506
+
159
- Interaction.cpp:103:17: error: use of undeclared identifier 'coh_force'
507
+ that_ave[0] = that_sum[0] / that_count;
508
+
509
+ that_ave[1] = that_sum[1] / that_count;
510
+
511
+
512
+
513
+ // 結合力 //
160
514
 
161
515
  dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
162
516
 
163
- ^
164
-
165
- Interaction.cpp:104:17: error: use of undeclared identifier 'coh_force'
166
-
167
517
  dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
168
518
 
519
+ }else{
520
+
521
+ // 結合力 //
522
+
523
+ dv_coh[0] = 0;
524
+
525
+ dv_coh[1] = 0;
526
+
169
- ^
527
+ }
528
+
529
+
530
+
170
-
531
+ return dv_coh;
532
+
533
+ }
534
+
535
+
536
+
537
+ //--- 一緒にいる人数の判定 ---//
538
+
539
+ int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
540
+
541
+ double my_posx = posx[num];
542
+
543
+ double my_posy = posy[num];
544
+
545
+ int withNum = 0;
546
+
547
+
548
+
549
+ for(int j=0; j<n; j++) {
550
+
551
+ if(num == j) continue;
552
+
553
+ // 個体間距離と角度を計算 //
554
+
555
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
556
+
171
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
557
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
558
+
172
-
559
+ if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
560
+
561
+ for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
562
+
563
+ if(friends[k] == j) withNum++; // 合流人数
564
+
565
+ }
566
+
567
+ }
568
+
569
+ }
570
+
571
+
572
+
173
- 20 errors generated.
573
+ return withNum;
574
+
575
+ }
174
576
 
175
577
  ```
176
-
177
-
178
-
179
- ### 該当のソースコード
180
-
181
-
182
-
183
- ```C++
184
-
185
- /* Interaction.hpp */
186
-
187
- #ifndef __CLASS__INTERACTION
188
-
189
-
190
-
191
- #include <cmath>
192
-
193
- #include <vector>
194
-
195
-
196
-
197
- #define __CLASS__INTERACTION
198
-
199
-
200
-
201
- //===== 相互作用クラス =====//
202
-
203
- class Interaction
204
-
205
- {
206
-
207
- public:
208
-
209
- int n;
210
-
211
- double sep_force;
212
-
213
- double sep_dis;
214
-
215
- double sep_angle;
216
-
217
- double coh_force;
218
-
219
- double coh_dis;
220
-
221
- double dis[36] = {};
222
-
223
- double angle[36] = {};
224
-
225
-
226
-
227
- //--- コンストラクタ ---//
228
-
229
- Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
230
-
231
- ~Interaction(); // デストラクタ
232
-
233
-
234
-
235
- //--- セッタ ---//
236
-
237
- void set(int nn, double sf, double sd, double sa, double cf, double cd);
238
-
239
-
240
-
241
- //--- 分離力計算 ---//
242
-
243
- double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
244
-
245
-
246
-
247
- //--- 結合力計算 ---//
248
-
249
- double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
250
-
251
-
252
-
253
- //--- 一緒にいる人数の判定 ---//
254
-
255
- int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
256
-
257
-
258
-
259
- //--- 距離計算 ----//
260
-
261
- double E_dis (double xi, double xj, double yi, double yj){
262
-
263
- double dis = 0;
264
-
265
- dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
266
-
267
- return dis;
268
-
269
- }
270
-
271
-
272
-
273
- //--- 角度計算 ---//
274
-
275
- double E_angle (double xi, double xj, double yi, double yj){
276
-
277
- double theta = 0;
278
-
279
- double rx = 0; // x距離
280
-
281
- double ry = 0; // y距離
282
-
283
- rx = xi - xj;
284
-
285
- ry = yi - yj;
286
-
287
- theta = atan2(ry, rx); // 個体間角度計算
288
-
289
-
290
-
291
- return theta;
292
-
293
- }
294
-
295
- };
296
-
297
-
298
-
299
- #endif
300
-
301
- ```
302
-
303
- ```C++
304
-
305
- /* Interaction.cpp */
306
-
307
- #include "Interaction.hpp"
308
-
309
-
310
-
311
- //--- コンストラクタ定義 ---//
312
-
313
- Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
314
-
315
- set(nn, sf, sd, sa, cf, cd);
316
-
317
- }
318
-
319
-
320
-
321
- /*
322
-
323
- //--- デストラクタ定義 ---//
324
-
325
- Interaction::~Interaction(){
326
-
327
- if(dis != NULL) delete [] dis;
328
-
329
- if(angle != NULL) delete [] angle;
330
-
331
- }
332
-
333
- */
334
-
335
-
336
-
337
- //--- セッタ ---//
338
-
339
- void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
340
-
341
- n = nn;
342
-
343
- sep_force = sf;
344
-
345
- sep_dis = sd;
346
-
347
- sep_angle = sa;
348
-
349
- coh_force = cf;
350
-
351
- coh_dis = cd;
352
-
353
- }
354
-
355
-
356
-
357
- //--- 分離力計算 ---//
358
-
359
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
360
-
361
- double that_sum[2] = {};
362
-
363
- double that_count = 0;
364
-
365
- double that_ave[2] = {};
366
-
367
- double dv_sep[2] = {};
368
-
369
- double my_posx = posx[num];
370
-
371
- double my_posy = posy[num];
372
-
373
-
374
-
375
- //--- 初期化 ---//
376
-
377
- that_sum[0] = 0;
378
-
379
- that_sum[1] = 0;
380
-
381
- that_count = 0;
382
-
383
-
384
-
385
- // 個体間距離と角度の計算 //
386
-
387
- for(int j = 0; j < n; j++) {
388
-
389
- if(num == j) continue;
390
-
391
- if(is_seat) continue; // 着席した人は力の影響を受けない
392
-
393
- if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
394
-
395
- // 個体間距離と角度を計算 //
396
-
397
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
398
-
399
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
400
-
401
-
402
-
403
- // 分離力の範囲内なら //
404
-
405
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
406
-
407
- // 範囲内の個体の座標を合計 //
408
-
409
- that_sum[0] += posx[j];
410
-
411
- that_sum[1] += posy[j];
412
-
413
- that_count += 1;
414
-
415
- }
416
-
417
- }
418
-
419
-
420
-
421
- // 範囲内の個体の平均座標 //
422
-
423
- if(that_count != 0){
424
-
425
- that_ave[0] = that_sum[0] / that_count;
426
-
427
- that_ave[1] = that_sum[1] / that_count;
428
-
429
-
430
-
431
- // 分離力 //
432
-
433
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
434
-
435
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
436
-
437
- }else{
438
-
439
- // 分離力 //
440
-
441
- dv_sep[0] = 0;
442
-
443
- dv_sep[1] = 0;
444
-
445
- }
446
-
447
-
448
-
449
- return dv_sep;
450
-
451
- }
452
-
453
-
454
-
455
- //--- 結合力計算 ---//
456
-
457
- double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
458
-
459
- double that_sum[2] = {};
460
-
461
- double that_count = 0;
462
-
463
- double that_ave[2] = {};
464
-
465
- double dv_coh[2] = {};
466
-
467
- double dis = 0;
468
-
469
- double angle = 0;
470
-
471
- double my_posx = posx[num];
472
-
473
- double my_posy = posy[num];
474
-
475
-
476
-
477
- for(int k=0; k<friends_num; k++){
478
-
479
- if(friends[k] == -1) continue;
480
-
481
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
482
-
483
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
484
-
485
- if(dis >= coh_dis){
486
-
487
- that_sum[0] += posx[friends[k]];
488
-
489
- that_sum[1] += posy[friends[k]];
490
-
491
- that_count++;
492
-
493
- }
494
-
495
- }
496
-
497
-
498
-
499
- // 範囲内の個体の平均座標 //
500
-
501
- if(that_count != 0){
502
-
503
- that_ave[0] = that_sum[0] / that_count;
504
-
505
- that_ave[1] = that_sum[1] / that_count;
506
-
507
-
508
-
509
- // 結合力 //
510
-
511
- dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
512
-
513
- dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
514
-
515
- }else{
516
-
517
- // 結合力 //
518
-
519
- dv_coh[0] = 0;
520
-
521
- dv_coh[1] = 0;
522
-
523
- }
524
-
525
-
526
-
527
- return dv_coh;
528
-
529
- }
530
-
531
-
532
-
533
- //--- 一緒にいる人数の判定 ---//
534
-
535
- int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
536
-
537
- double my_posx = posx[num];
538
-
539
- double my_posy = posy[num];
540
-
541
- int withNum = 0;
542
-
543
-
544
-
545
- for(int j=0; j<n; j++) {
546
-
547
- if(num == j) continue;
548
-
549
- // 個体間距離と角度を計算 //
550
-
551
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
552
-
553
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
554
-
555
- if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
556
-
557
- for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
558
-
559
- if(friends[k] == j) withNum++; // 合流人数
560
-
561
- }
562
-
563
- }
564
-
565
- }
566
-
567
-
568
-
569
- return withNum;
570
-
571
- }
572
-
573
-
574
-
575
- ```

7

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

2021/10/15 05:00

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
@@ -1 +1 @@
1
- オブジェクト指向についての勉強が浅くなぜエラーが出ているのか分かりません
1
+ オブジェクト指向についての勉強が浅くなぜ未定義エラーが出ているのか分かりません
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  コンストラクタを設定しているはずなのに変数やメソッドのエラーが出ます。
8
8
 
9
- オブジェクト指向についての勉強が浅くなぜエラーが出ているのか分かりません
9
+ オブジェクト指向についての勉強が浅くなぜコンストラクタでセットしている部分の未定義エラーが出ているのか分かりません
10
10
 
11
11
  教えていただけると助かります。
12
12
 
@@ -38,554 +38,538 @@
38
38
 
39
39
  ```
40
40
 
41
+ Interaction.cpp:41:22: error: use of undeclared identifier 'n'
42
+
43
+ for(int j = 0; j < n; j++) {
44
+
45
+ ^
46
+
47
+ Interaction.cpp:46:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
48
+
49
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
50
+
51
+ ^~~
52
+
53
+ div
54
+
55
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
56
+
57
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
58
+
59
+ ^
60
+
61
+ Interaction.cpp:46:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
62
+
63
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
64
+
65
+ ^~~
66
+
67
+ Interaction.cpp:46:14: error: use of undeclared identifier 'E_dis'
68
+
69
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
70
+
71
+ ^
72
+
73
+ Interaction.cpp:47:5: error: use of undeclared identifier 'angle'
74
+
75
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
76
+
77
+ ^
78
+
79
+ Interaction.cpp:47:16: error: use of undeclared identifier 'E_angle'
80
+
81
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
82
+
83
+ ^
84
+
85
+ Interaction.cpp:50:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
86
+
87
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
88
+
89
+ ^~~
90
+
91
+ div
92
+
93
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
94
+
95
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
96
+
97
+ ^
98
+
99
+ Interaction.cpp:50:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
100
+
101
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
102
+
103
+ ^~~
104
+
105
+ Interaction.cpp:50:18: error: use of undeclared identifier 'sep_dis'
106
+
107
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
108
+
109
+ ^
110
+
111
+ Interaction.cpp:50:29: error: use of undeclared identifier 'angle'
112
+
113
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
114
+
115
+ ^
116
+
117
+ Interaction.cpp:50:41: error: use of undeclared identifier 'sep_angle'
118
+
119
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
120
+
121
+ ^
122
+
123
+ Interaction.cpp:64:17: error: use of undeclared identifier 'sep_force'
124
+
125
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
126
+
127
+ ^
128
+
129
+ Interaction.cpp:65:17: error: use of undeclared identifier 'sep_force'
130
+
131
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
132
+
133
+ ^
134
+
41
- Interaction.cpp:10:6: warning: comparison of array 'this->dis' not equal to a null pointer is always true [-Wtautological-pointer-compare]
135
+ Interaction.cpp:72:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
136
+
137
+ return dv_sep;
138
+
139
+ ^~~~~~
140
+
141
+ Interaction.cpp:88:11: error: use of undeclared identifier 'E_dis'
142
+
143
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
144
+
145
+ ^
146
+
147
+ Interaction.cpp:89:13: error: use of undeclared identifier 'E_angle'
148
+
149
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
150
+
151
+ ^
152
+
153
+ Interaction.cpp:90:15: error: use of undeclared identifier 'coh_dis'
154
+
155
+ if(dis >= coh_dis){
156
+
157
+ ^
158
+
159
+ Interaction.cpp:103:17: error: use of undeclared identifier 'coh_force'
160
+
161
+ dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
162
+
163
+ ^
164
+
165
+ Interaction.cpp:104:17: error: use of undeclared identifier 'coh_force'
166
+
167
+ dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
168
+
169
+ ^
170
+
171
+ fatal error: too many errors emitted, stopping now [-ferror-limit=]
172
+
173
+ 20 errors generated.
174
+
175
+ ```
176
+
177
+
178
+
179
+ ### 該当のソースコード
180
+
181
+
182
+
183
+ ```C++
184
+
185
+ /* Interaction.hpp */
186
+
187
+ #ifndef __CLASS__INTERACTION
188
+
189
+
190
+
191
+ #include <cmath>
192
+
193
+ #include <vector>
194
+
195
+
196
+
197
+ #define __CLASS__INTERACTION
198
+
199
+
200
+
201
+ //===== 相互作用クラス =====//
202
+
203
+ class Interaction
204
+
205
+ {
206
+
207
+ public:
208
+
209
+ int n;
210
+
211
+ double sep_force;
212
+
213
+ double sep_dis;
214
+
215
+ double sep_angle;
216
+
217
+ double coh_force;
218
+
219
+ double coh_dis;
220
+
221
+ double dis[36] = {};
222
+
223
+ double angle[36] = {};
224
+
225
+
226
+
227
+ //--- コンストラクタ ---//
228
+
229
+ Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
230
+
231
+ ~Interaction(); // デストラクタ
232
+
233
+
234
+
235
+ //--- セッタ ---//
236
+
237
+ void set(int nn, double sf, double sd, double sa, double cf, double cd);
238
+
239
+
240
+
241
+ //--- 分離力計算 ---//
242
+
243
+ double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
244
+
245
+
246
+
247
+ //--- 結合力計算 ---//
248
+
249
+ double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
250
+
251
+
252
+
253
+ //--- 一緒にいる人数の判定 ---//
254
+
255
+ int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
256
+
257
+
258
+
259
+ //--- 距離計算 ----//
260
+
261
+ double E_dis (double xi, double xj, double yi, double yj){
262
+
263
+ double dis = 0;
264
+
265
+ dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
266
+
267
+ return dis;
268
+
269
+ }
270
+
271
+
272
+
273
+ //--- 角度計算 ---//
274
+
275
+ double E_angle (double xi, double xj, double yi, double yj){
276
+
277
+ double theta = 0;
278
+
279
+ double rx = 0; // x距離
280
+
281
+ double ry = 0; // y距離
282
+
283
+ rx = xi - xj;
284
+
285
+ ry = yi - yj;
286
+
287
+ theta = atan2(ry, rx); // 個体間角度計算
288
+
289
+
290
+
291
+ return theta;
292
+
293
+ }
294
+
295
+ };
296
+
297
+
298
+
299
+ #endif
300
+
301
+ ```
302
+
303
+ ```C++
304
+
305
+ /* Interaction.cpp */
306
+
307
+ #include "Interaction.hpp"
308
+
309
+
310
+
311
+ //--- コンストラクタ定義 ---//
312
+
313
+ Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
314
+
315
+ set(nn, sf, sd, sa, cf, cd);
316
+
317
+ }
318
+
319
+
320
+
321
+ /*
322
+
323
+ //--- デストラクタ定義 ---//
324
+
325
+ Interaction::~Interaction(){
42
326
 
43
327
  if(dis != NULL) delete [] dis;
44
328
 
45
- ^~~ ~~~~
46
-
47
- Interaction.cpp:10:19: error: cannot delete expression of type 'double [36]'
48
-
49
- if(dis != NULL) delete [] dis;
50
-
51
- ^ ~~~
52
-
53
- Interaction.cpp:11:6: warning: comparison of array 'this->angle' not equal to a null pointer is always true [-Wtautological-pointer-compare]
54
-
55
329
  if(angle != NULL) delete [] angle;
56
330
 
331
+ }
332
+
57
- ^~~~~ ~~~~
333
+ */
334
+
335
+
336
+
58
-
337
+ //--- セッタ ---//
338
+
59
- Interaction.cpp:11:21: error: cannot delete expression of type 'double [36]'
339
+ void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
340
+
60
-
341
+ n = nn;
342
+
343
+ sep_force = sf;
344
+
345
+ sep_dis = sd;
346
+
347
+ sep_angle = sa;
348
+
349
+ coh_force = cf;
350
+
351
+ coh_dis = cd;
352
+
353
+ }
354
+
355
+
356
+
357
+ //--- 分離力計算 ---//
358
+
359
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
360
+
361
+ double that_sum[2] = {};
362
+
363
+ double that_count = 0;
364
+
365
+ double that_ave[2] = {};
366
+
367
+ double dv_sep[2] = {};
368
+
61
- if(angle != NULL) delete [] angle;
369
+ double my_posx = posx[num];
370
+
62
-
371
+ double my_posy = posy[num];
372
+
373
+
374
+
375
+ //--- 初期化 ---//
376
+
377
+ that_sum[0] = 0;
378
+
379
+ that_sum[1] = 0;
380
+
63
- ^ ~~~~~
381
+ that_count = 0;
64
-
382
+
383
+
384
+
65
- Interaction.cpp:39:22: error: use of undeclared identifier 'n'
385
+ // 個体間距離と角度の計算 //
66
386
 
67
387
  for(int j = 0; j < n; j++) {
68
388
 
69
- ^
70
-
71
- Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
389
+ if(num == j) continue;
72
-
390
+
73
- if(is_seated) continue; // 着席した人は力の影響を受けない
391
+ if(is_seat) continue; // 着席した人は力の影響を受けない
74
-
75
- ^~~~~~~~~
392
+
76
-
77
- is_seat
78
-
79
- Interaction.cpp:25:110: note: 'is_seat' declared here
393
+ if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
80
-
81
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
394
+
82
-
83
- ^
84
-
85
- Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
395
+ // 個体間距離と角度を計算 //
86
396
 
87
397
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
88
398
 
89
- ^~~
90
-
91
- div
92
-
93
- /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
94
-
95
- inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
399
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
400
+
401
+
402
+
96
-
403
+ // 分離力の範囲内なら //
404
+
405
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
406
+
407
+ // 範囲内の個体の座標を合計 //
408
+
409
+ that_sum[0] += posx[j];
410
+
411
+ that_sum[1] += posy[j];
412
+
413
+ that_count += 1;
414
+
97
- ^
415
+ }
416
+
98
-
417
+ }
418
+
419
+
420
+
421
+ // 範囲内の個体の平均座標 //
422
+
423
+ if(that_count != 0){
424
+
425
+ that_ave[0] = that_sum[0] / that_count;
426
+
427
+ that_ave[1] = that_sum[1] / that_count;
428
+
429
+
430
+
431
+ // 分離力 //
432
+
433
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
434
+
435
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
436
+
437
+ }else{
438
+
439
+ // 分離力 //
440
+
441
+ dv_sep[0] = 0;
442
+
443
+ dv_sep[1] = 0;
444
+
445
+ }
446
+
447
+
448
+
449
+ return dv_sep;
450
+
451
+ }
452
+
453
+
454
+
455
+ //--- 結合力計算 ---//
456
+
457
+ double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
458
+
459
+ double that_sum[2] = {};
460
+
461
+ double that_count = 0;
462
+
463
+ double that_ave[2] = {};
464
+
465
+ double dv_coh[2] = {};
466
+
467
+ double dis = 0;
468
+
469
+ double angle = 0;
470
+
471
+ double my_posx = posx[num];
472
+
473
+ double my_posy = posy[num];
474
+
475
+
476
+
477
+ for(int k=0; k<friends_num; k++){
478
+
479
+ if(friends[k] == -1) continue;
480
+
481
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
482
+
483
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
484
+
485
+ if(dis >= coh_dis){
486
+
487
+ that_sum[0] += posx[friends[k]];
488
+
489
+ that_sum[1] += posy[friends[k]];
490
+
491
+ that_count++;
492
+
493
+ }
494
+
495
+ }
496
+
497
+
498
+
499
+ // 範囲内の個体の平均座標 //
500
+
501
+ if(that_count != 0){
502
+
503
+ that_ave[0] = that_sum[0] / that_count;
504
+
505
+ that_ave[1] = that_sum[1] / that_count;
506
+
507
+
508
+
509
+ // 結合力 //
510
+
511
+ dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
512
+
513
+ dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
514
+
515
+ }else{
516
+
517
+ // 結合力 //
518
+
519
+ dv_coh[0] = 0;
520
+
521
+ dv_coh[1] = 0;
522
+
523
+ }
524
+
525
+
526
+
527
+ return dv_coh;
528
+
529
+ }
530
+
531
+
532
+
533
+ //--- 一緒にいる人数の判定 ---//
534
+
99
- Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
535
+ int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
536
+
537
+ double my_posx = posx[num];
538
+
539
+ double my_posy = posy[num];
540
+
541
+ int withNum = 0;
542
+
543
+
544
+
545
+ for(int j=0; j<n; j++) {
546
+
547
+ if(num == j) continue;
548
+
549
+ // 個体間距離と角度を計算 //
100
550
 
101
551
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
102
552
 
103
- ^~~
104
-
105
- Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
106
-
107
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
108
-
109
- ^
110
-
111
- Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
112
-
113
553
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
114
554
 
115
- ^
116
-
117
- Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
118
-
119
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
120
-
121
- ^
122
-
123
- Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
124
-
125
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
555
+ if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
126
-
127
- ^~~
556
+
128
-
129
- div
130
-
131
- /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
132
-
133
- inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
134
-
135
- ^
136
-
137
- Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
138
-
139
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
140
-
141
- ^~~
142
-
143
- Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
144
-
145
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
146
-
147
- ^
148
-
149
- Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
150
-
151
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
152
-
153
- ^
154
-
155
- Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
156
-
157
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
158
-
159
- ^
160
-
161
- Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
162
-
163
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
557
+ for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
164
-
165
- ^
558
+
166
-
167
- Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
168
-
169
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
559
+ if(friends[k] == j) withNum++; // 合流人数
170
-
560
+
171
- ^
561
+ }
172
-
562
+
173
- Interaction.cpp:70:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
563
+ }
564
+
174
-
565
+ }
566
+
567
+
568
+
175
- return dv_sep;
569
+ return withNum;
176
-
177
- ^~~~~~
570
+
178
-
179
- Interaction.cpp:86:11: error: use of undeclared identifier 'E_dis'
180
-
181
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
182
-
183
- ^
571
+ }
184
-
185
- Interaction.cpp:87:13: error: use of undeclared identifier 'E_angle'
186
-
187
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
188
-
189
- ^
190
-
191
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
192
-
193
- 2 warnings and 20 errors generated.
194
572
 
195
573
 
196
574
 
197
575
  ```
198
-
199
-
200
-
201
- ### 該当のソースコード
202
-
203
-
204
-
205
- ```C++
206
-
207
- /* Interaction.hpp */
208
-
209
- #ifndef __CLASS__INTERACTION
210
-
211
-
212
-
213
- #include <cmath>
214
-
215
- #include <vector>
216
-
217
-
218
-
219
- #define __CLASS__INTERACTION
220
-
221
-
222
-
223
- //===== 相互作用クラス =====//
224
-
225
- class Interaction
226
-
227
- {
228
-
229
- public:
230
-
231
- int n;
232
-
233
- double sep_force;
234
-
235
- double sep_dis;
236
-
237
- double sep_angle;
238
-
239
- double coh_force;
240
-
241
- double coh_dis;
242
-
243
- double dis[36] = {};
244
-
245
- double angle[36] = {};
246
-
247
-
248
-
249
- //--- コンストラクタ ---//
250
-
251
- Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
252
-
253
- ~Interaction(); // デストラクタ
254
-
255
-
256
-
257
- //--- セッタ ---//
258
-
259
- void set(int nn, double sf, double sd, double sa, double cf, double cd);
260
-
261
-
262
-
263
- //--- 分離力計算 ---//
264
-
265
- double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
266
-
267
-
268
-
269
- //--- 結合力計算 ---//
270
-
271
- double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
272
-
273
-
274
-
275
- //--- 一緒にいる人数の判定 ---//
276
-
277
- int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
278
-
279
-
280
-
281
- //--- 距離計算 ----//
282
-
283
- double E_dis (double xi, double xj, double yi, double yj){
284
-
285
- double dis = 0;
286
-
287
- dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
288
-
289
- return dis;
290
-
291
- }
292
-
293
-
294
-
295
- //--- 角度計算 ---//
296
-
297
- double E_angle (double xi, double xj, double yi, double yj){
298
-
299
- double theta = 0;
300
-
301
- double rx = 0; // x距離
302
-
303
- double ry = 0; // y距離
304
-
305
- rx = xi - xj;
306
-
307
- ry = yi - yj;
308
-
309
- theta = atan2(ry, rx); // 個体間角度計算
310
-
311
-
312
-
313
- return theta;
314
-
315
- }
316
-
317
- };
318
-
319
-
320
-
321
- #endif
322
-
323
- ```
324
-
325
- ```C++
326
-
327
- /* Interaction.cpp */
328
-
329
- #include "Interaction.hpp"
330
-
331
-
332
-
333
- //--- コンストラクタ定義 ---//
334
-
335
- Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
336
-
337
- set(nn, sf, sd, sa, cf, cd);
338
-
339
- }
340
-
341
-
342
-
343
- //--- デストラクタ定義 ---//
344
-
345
- Interaction::~Interaction(){
346
-
347
- if(dis != NULL) delete [] dis;
348
-
349
- if(angle != NULL) delete [] angle;
350
-
351
- }
352
-
353
-
354
-
355
- //--- セッタ ---//
356
-
357
- void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
358
-
359
- n = nn;
360
-
361
- sep_force = sf;
362
-
363
- sep_dis = sd;
364
-
365
- sep_angle = sa;
366
-
367
- coh_force = cf;
368
-
369
- coh_dis = cd;
370
-
371
- }
372
-
373
-
374
-
375
- //--- 分離力計算 ---//
376
-
377
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
378
-
379
- double that_sum[2] = {};
380
-
381
- double that_count = 0;
382
-
383
- double that_ave[2] = {};
384
-
385
- double dv_sep[2] = {};
386
-
387
- double my_posx = posx[num];
388
-
389
- double my_posy = posy[num];
390
-
391
-
392
-
393
- //--- 初期化 ---//
394
-
395
- that_sum[0] = 0;
396
-
397
- that_sum[1] = 0;
398
-
399
- that_count = 0;
400
-
401
-
402
-
403
- // 個体間距離と角度の計算 //
404
-
405
- for(int j = 0; j < n; j++) {
406
-
407
- if(num == j) continue;
408
-
409
- if(is_seated) continue; // 着席した人は力の影響を受けない
410
-
411
- if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
412
-
413
- // 個体間距離と角度を計算 //
414
-
415
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
416
-
417
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
418
-
419
-
420
-
421
- // 分離力の範囲内なら //
422
-
423
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
424
-
425
- // 範囲内の個体の座標を合計 //
426
-
427
- that_sum[0] += posx[j];
428
-
429
- that_sum[1] += posy[j];
430
-
431
- that_count += 1;
432
-
433
- }
434
-
435
- }
436
-
437
-
438
-
439
- // 範囲内の個体の平均座標 //
440
-
441
- if(that_count != 0){
442
-
443
- that_ave[0] = that_sum[0] / that_count;
444
-
445
- that_ave[1] = that_sum[1] / that_count;
446
-
447
-
448
-
449
- // 分離力 //
450
-
451
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
452
-
453
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
454
-
455
- }else{
456
-
457
- // 分離力 //
458
-
459
- dv_sep[0] = 0;
460
-
461
- dv_sep[1] = 0;
462
-
463
- }
464
-
465
-
466
-
467
- return dv_sep;
468
-
469
- }
470
-
471
-
472
-
473
- //--- 結合力計算 ---//
474
-
475
- double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
476
-
477
- double that_sum[2] = {};
478
-
479
- double that_count = 0;
480
-
481
- double that_ave[2] = {};
482
-
483
- double dv_coh[2] = {};
484
-
485
- double dis = 0;
486
-
487
- double angle = 0;
488
-
489
- double my_posx = posx[num];
490
-
491
- double my_posy = posy[num];
492
-
493
-
494
-
495
- for(int k=0; k<friends_num; k++){
496
-
497
- if(friends[k] == -1) continue;
498
-
499
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
500
-
501
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
502
-
503
- if(dis >= coh_dis){
504
-
505
- that_sum[0] += posx[friends[k]];
506
-
507
- that_sum[1] += posy[friends[k]];
508
-
509
- that_count++;
510
-
511
- }
512
-
513
- }
514
-
515
-
516
-
517
- // 範囲内の個体の平均座標 //
518
-
519
- if(that_count != 0){
520
-
521
- that_ave[0] = that_sum[0] / that_count;
522
-
523
- that_ave[1] = that_sum[1] / that_count;
524
-
525
-
526
-
527
- // 結合力 //
528
-
529
- dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
530
-
531
- dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
532
-
533
- }else{
534
-
535
- // 結合力 //
536
-
537
- dv_coh[0] = 0;
538
-
539
- dv_coh[1] = 0;
540
-
541
- }
542
-
543
-
544
-
545
- return dv_coh;
546
-
547
- }
548
-
549
-
550
-
551
- //--- 一緒にいる人数の判定 ---//
552
-
553
- int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
554
-
555
- double my_posx = posx[num];
556
-
557
- double my_posy = posy[num];
558
-
559
- int withNum = 0;
560
-
561
-
562
-
563
- for(int j=0; j<n; j++) {
564
-
565
- if(num == j) continue;
566
-
567
- // 個体間距離と角度を計算 //
568
-
569
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
570
-
571
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
572
-
573
- if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
574
-
575
- for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
576
-
577
- if(friends[k] == j) withNum++; // 合流人数
578
-
579
- }
580
-
581
- }
582
-
583
- }
584
-
585
-
586
-
587
- return withNum;
588
-
589
- }
590
-
591
- ```

6

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

2021/10/15 04:34

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -38,544 +38,554 @@
38
38
 
39
39
  ```
40
40
 
41
+ Interaction.cpp:10:6: warning: comparison of array 'this->dis' not equal to a null pointer is always true [-Wtautological-pointer-compare]
42
+
43
+ if(dis != NULL) delete [] dis;
44
+
45
+ ^~~ ~~~~
46
+
47
+ Interaction.cpp:10:19: error: cannot delete expression of type 'double [36]'
48
+
49
+ if(dis != NULL) delete [] dis;
50
+
51
+ ^ ~~~
52
+
53
+ Interaction.cpp:11:6: warning: comparison of array 'this->angle' not equal to a null pointer is always true [-Wtautological-pointer-compare]
54
+
55
+ if(angle != NULL) delete [] angle;
56
+
57
+ ^~~~~ ~~~~
58
+
59
+ Interaction.cpp:11:21: error: cannot delete expression of type 'double [36]'
60
+
61
+ if(angle != NULL) delete [] angle;
62
+
63
+ ^ ~~~~~
64
+
65
+ Interaction.cpp:39:22: error: use of undeclared identifier 'n'
66
+
67
+ for(int j = 0; j < n; j++) {
68
+
69
+ ^
70
+
71
+ Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
72
+
73
+ if(is_seated) continue; // 着席した人は力の影響を受けない
74
+
75
+ ^~~~~~~~~
76
+
77
+ is_seat
78
+
79
+ Interaction.cpp:25:110: note: 'is_seat' declared here
80
+
81
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
82
+
83
+ ^
84
+
85
+ Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
86
+
87
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
88
+
89
+ ^~~
90
+
91
+ div
92
+
93
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
94
+
95
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
96
+
97
+ ^
98
+
99
+ Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
100
+
101
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
102
+
103
+ ^~~
104
+
105
+ Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
106
+
107
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
108
+
109
+ ^
110
+
111
+ Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
112
+
113
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
114
+
115
+ ^
116
+
117
+ Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
118
+
119
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
120
+
121
+ ^
122
+
123
+ Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
124
+
125
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
126
+
127
+ ^~~
128
+
129
+ div
130
+
131
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
132
+
133
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
134
+
135
+ ^
136
+
137
+ Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
138
+
139
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
140
+
141
+ ^~~
142
+
41
- ./Interaction.cpp:4:1: error: use of undeclared identifier 'Interaction'
143
+ Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
144
+
145
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
146
+
147
+ ^
148
+
149
+ Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
150
+
151
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
152
+
153
+ ^
154
+
155
+ Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
156
+
157
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
158
+
159
+ ^
160
+
161
+ Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
162
+
163
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
164
+
165
+ ^
166
+
167
+ Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
168
+
169
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
170
+
171
+ ^
172
+
173
+ Interaction.cpp:70:10: error: cannot initialize return object of type 'double Interaction::*' with an lvalue of type 'double [2]'
174
+
175
+ return dv_sep;
176
+
177
+ ^~~~~~
178
+
179
+ Interaction.cpp:86:11: error: use of undeclared identifier 'E_dis'
180
+
181
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
182
+
183
+ ^
184
+
185
+ Interaction.cpp:87:13: error: use of undeclared identifier 'E_angle'
186
+
187
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
188
+
189
+ ^
190
+
191
+ fatal error: too many errors emitted, stopping now [-ferror-limit=]
192
+
193
+ 2 warnings and 20 errors generated.
194
+
195
+
196
+
197
+ ```
198
+
199
+
200
+
201
+ ### 該当のソースコード
202
+
203
+
204
+
205
+ ```C++
206
+
207
+ /* Interaction.hpp */
208
+
209
+ #ifndef __CLASS__INTERACTION
210
+
211
+
212
+
213
+ #include <cmath>
214
+
215
+ #include <vector>
216
+
217
+
218
+
219
+ #define __CLASS__INTERACTION
220
+
221
+
222
+
223
+ //===== 相互作用クラス =====//
224
+
225
+ class Interaction
226
+
227
+ {
228
+
229
+ public:
230
+
231
+ int n;
232
+
233
+ double sep_force;
234
+
235
+ double sep_dis;
236
+
237
+ double sep_angle;
238
+
239
+ double coh_force;
240
+
241
+ double coh_dis;
242
+
243
+ double dis[36] = {};
244
+
245
+ double angle[36] = {};
246
+
247
+
248
+
249
+ //--- コンストラクタ ---//
250
+
251
+ Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
252
+
253
+ ~Interaction(); // デストラクタ
254
+
255
+
256
+
257
+ //--- セッタ ---//
258
+
259
+ void set(int nn, double sf, double sd, double sa, double cf, double cd);
260
+
261
+
262
+
263
+ //--- 分離力計算 ---//
264
+
265
+ double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
266
+
267
+
268
+
269
+ //--- 結合力計算 ---//
270
+
271
+ double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
272
+
273
+
274
+
275
+ //--- 一緒にいる人数の判定 ---//
276
+
277
+ int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
278
+
279
+
280
+
281
+ //--- 距離計算 ----//
282
+
283
+ double E_dis (double xi, double xj, double yi, double yj){
284
+
285
+ double dis = 0;
286
+
287
+ dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
288
+
289
+ return dis;
290
+
291
+ }
292
+
293
+
294
+
295
+ //--- 角度計算 ---//
296
+
297
+ double E_angle (double xi, double xj, double yi, double yj){
298
+
299
+ double theta = 0;
300
+
301
+ double rx = 0; // x距離
302
+
303
+ double ry = 0; // y距離
304
+
305
+ rx = xi - xj;
306
+
307
+ ry = yi - yj;
308
+
309
+ theta = atan2(ry, rx); // 個体間角度計算
310
+
311
+
312
+
313
+ return theta;
314
+
315
+ }
316
+
317
+ };
318
+
319
+
320
+
321
+ #endif
322
+
323
+ ```
324
+
325
+ ```C++
326
+
327
+ /* Interaction.cpp */
328
+
329
+ #include "Interaction.hpp"
330
+
331
+
332
+
333
+ //--- コンストラクタ定義 ---//
42
334
 
43
335
  Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
44
336
 
337
+ set(nn, sf, sd, sa, cf, cd);
338
+
45
- ^
339
+ }
46
-
340
+
341
+
342
+
47
- ./Interaction.cpp:9:1: error: use of undeclared identifier 'Interaction'
343
+ //--- デストラクタ定義 ---//
48
344
 
49
345
  Interaction::~Interaction(){
50
346
 
347
+ if(dis != NULL) delete [] dis;
348
+
349
+ if(angle != NULL) delete [] angle;
350
+
51
- ^
351
+ }
52
-
352
+
353
+
354
+
53
- ./Interaction.cpp:15:6: error: use of undeclared identifier 'Interaction'
355
+ //--- セッタ ---//
54
356
 
55
357
  void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
56
358
 
359
+ n = nn;
360
+
361
+ sep_force = sf;
362
+
363
+ sep_dis = sd;
364
+
365
+ sep_angle = sa;
366
+
367
+ coh_force = cf;
368
+
369
+ coh_dis = cd;
370
+
57
- ^
371
+ }
58
-
372
+
373
+
374
+
59
- ./Interaction.cpp:25:8: error: use of undeclared identifier 'Interaction'
375
+ //--- 分離力計算 ---//
60
376
 
61
377
  double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
62
378
 
379
+ double that_sum[2] = {};
380
+
381
+ double that_count = 0;
382
+
383
+ double that_ave[2] = {};
384
+
385
+ double dv_sep[2] = {};
386
+
387
+ double my_posx = posx[num];
388
+
389
+ double my_posy = posy[num];
390
+
391
+
392
+
393
+ //--- 初期化 ---//
394
+
395
+ that_sum[0] = 0;
396
+
397
+ that_sum[1] = 0;
398
+
63
- ^
399
+ that_count = 0;
64
-
400
+
401
+
402
+
65
- ./Interaction.cpp:39:22: error: use of undeclared identifier 'n'
403
+ // 個体間距離と角度の計算 //
66
404
 
67
405
  for(int j = 0; j < n; j++) {
68
406
 
69
- ^
70
-
71
- ./Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
407
+ if(num == j) continue;
72
408
 
73
409
  if(is_seated) continue; // 着席した人は力の影響を受けない
74
410
 
75
- ^~~~~~~~~
76
-
77
- is_seat
78
-
79
- ./Interaction.cpp:25:110: note: 'is_seat' declared here
411
+ if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
80
-
81
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
412
+
82
-
83
- ^
84
-
85
- ./Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
413
+ // 個体間距離と角度を計算 //
86
414
 
87
415
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
88
416
 
89
- ^~~
90
-
91
- div
92
-
93
- /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
94
-
95
- inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
417
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
418
+
419
+
420
+
96
-
421
+ // 分離力の範囲内なら //
422
+
423
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
424
+
425
+ // 範囲内の個体の座標を合計 //
426
+
427
+ that_sum[0] += posx[j];
428
+
429
+ that_sum[1] += posy[j];
430
+
431
+ that_count += 1;
432
+
97
- ^
433
+ }
434
+
98
-
435
+ }
436
+
437
+
438
+
439
+ // 範囲内の個体の平均座標 //
440
+
441
+ if(that_count != 0){
442
+
99
- In file included from classroomExit1.cpp:12:
443
+ that_ave[0] = that_sum[0] / that_count;
444
+
100
-
445
+ that_ave[1] = that_sum[1] / that_count;
446
+
447
+
448
+
449
+ // 分離力 //
450
+
451
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
452
+
453
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
454
+
455
+ }else{
456
+
457
+ // 分離力 //
458
+
459
+ dv_sep[0] = 0;
460
+
461
+ dv_sep[1] = 0;
462
+
463
+ }
464
+
465
+
466
+
467
+ return dv_sep;
468
+
469
+ }
470
+
471
+
472
+
473
+ //--- 結合力計算 ---//
474
+
101
- ./Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
475
+ double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
476
+
477
+ double that_sum[2] = {};
478
+
479
+ double that_count = 0;
480
+
481
+ double that_ave[2] = {};
482
+
483
+ double dv_coh[2] = {};
484
+
485
+ double dis = 0;
486
+
487
+ double angle = 0;
488
+
489
+ double my_posx = posx[num];
490
+
491
+ double my_posy = posy[num];
492
+
493
+
494
+
495
+ for(int k=0; k<friends_num; k++){
496
+
497
+ if(friends[k] == -1) continue;
498
+
499
+ dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
500
+
501
+ angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
502
+
503
+ if(dis >= coh_dis){
504
+
505
+ that_sum[0] += posx[friends[k]];
506
+
507
+ that_sum[1] += posy[friends[k]];
508
+
509
+ that_count++;
510
+
511
+ }
512
+
513
+ }
514
+
515
+
516
+
517
+ // 範囲内の個体の平均座標 //
518
+
519
+ if(that_count != 0){
520
+
521
+ that_ave[0] = that_sum[0] / that_count;
522
+
523
+ that_ave[1] = that_sum[1] / that_count;
524
+
525
+
526
+
527
+ // 結合力 //
528
+
529
+ dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
530
+
531
+ dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
532
+
533
+ }else{
534
+
535
+ // 結合力 //
536
+
537
+ dv_coh[0] = 0;
538
+
539
+ dv_coh[1] = 0;
540
+
541
+ }
542
+
543
+
544
+
545
+ return dv_coh;
546
+
547
+ }
548
+
549
+
550
+
551
+ //--- 一緒にいる人数の判定 ---//
552
+
553
+ int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
554
+
555
+ double my_posx = posx[num];
556
+
557
+ double my_posy = posy[num];
558
+
559
+ int withNum = 0;
560
+
561
+
562
+
563
+ for(int j=0; j<n; j++) {
564
+
565
+ if(num == j) continue;
566
+
567
+ // 個体間距離と角度を計算 //
102
568
 
103
569
  dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
104
570
 
105
- ^~~
106
-
107
- ./Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
108
-
109
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
110
-
111
- ^
112
-
113
- ./Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
114
-
115
571
  angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
116
572
 
117
- ^
118
-
119
- ./Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
120
-
121
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
122
-
123
- ^
124
-
125
- ./Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
126
-
127
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
573
+ if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
128
-
129
- ^~~
574
+
130
-
131
- div
132
-
133
- /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
134
-
135
- inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
136
-
137
- ^
138
-
139
- In file included from classroomExit1.cpp:12:
140
-
141
- ./Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
142
-
143
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
144
-
145
- ^~~
146
-
147
- ./Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
148
-
149
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
150
-
151
- ^
152
-
153
- ./Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
154
-
155
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
156
-
157
- ^
158
-
159
- ./Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
160
-
161
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
162
-
163
- ^
164
-
165
- ./Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
166
-
167
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
575
+ for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
168
-
169
- ^
576
+
170
-
171
- ./Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
172
-
173
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
577
+ if(friends[k] == j) withNum++; // 合流人数
174
-
578
+
175
- ^
579
+ }
176
-
580
+
177
- ./Interaction.cpp:70:10: error: cannot initialize return object of type 'double' with an lvalue of type 'double [2]'
581
+ }
582
+
178
-
583
+ }
584
+
585
+
586
+
179
- return dv_sep;
587
+ return withNum;
180
-
588
+
181
- ^~~~~~
589
+ }
182
-
183
- fatal error: too many errors emitted, stopping now [-ferror-limit=]
184
-
185
- 20 errors generated.
186
590
 
187
591
  ```
188
-
189
-
190
-
191
- ### 該当のソースコード
192
-
193
-
194
-
195
- ```C++
196
-
197
- /* Interaction.hpp */
198
-
199
- #ifndef __CLASS__INTERACTION
200
-
201
-
202
-
203
- #include <cmath>
204
-
205
- #include <vector>
206
-
207
-
208
-
209
- #define __CLASS__INTERACTION
210
-
211
-
212
-
213
- //===== 相互作用クラス =====//
214
-
215
- class Interaction
216
-
217
- {
218
-
219
- public:
220
-
221
- int n;
222
-
223
- double sep_force;
224
-
225
- double sep_dis;
226
-
227
- double sep_angle;
228
-
229
- double coh_force;
230
-
231
- double coh_dis;
232
-
233
- double dis[36] = {};
234
-
235
- double angle[36] = {};
236
-
237
-
238
-
239
- //--- コンストラクタ ---//
240
-
241
- Interaction(int nn, double sf, double sd, double sa, double cf, double cd);
242
-
243
- ~Interaction(); // デストラクタ
244
-
245
-
246
-
247
- //--- セッタ ---//
248
-
249
- void set(int nn, double sf, double sd, double sa, double cf, double cd);
250
-
251
-
252
-
253
- //--- 分離力計算 ---//
254
-
255
- double *CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seated, const bool is_group);
256
-
257
-
258
-
259
- //--- 結合力計算 ---//
260
-
261
- double *CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
262
-
263
-
264
-
265
- //--- 一緒にいる人数の判定 ---//
266
-
267
- int CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]);
268
-
269
-
270
-
271
- //--- 距離計算 ----//
272
-
273
- double E_dis (double xi, double xj, double yi, double yj){
274
-
275
- double dis = 0;
276
-
277
- dis = sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj));
278
-
279
- return dis;
280
-
281
- }
282
-
283
-
284
-
285
- //--- 角度計算 ---//
286
-
287
- double E_angle (double xi, double xj, double yi, double yj){
288
-
289
- double theta = 0;
290
-
291
- double rx = 0; // x距離
292
-
293
- double ry = 0; // y距離
294
-
295
- rx = xi - xj;
296
-
297
- ry = yi - yj;
298
-
299
- theta = atan2(ry, rx); // 個体間角度計算
300
-
301
-
302
-
303
- return theta;
304
-
305
- }
306
-
307
- };
308
-
309
-
310
-
311
- #endif
312
-
313
- ```
314
-
315
- ```C++
316
-
317
- /* Interaction.cpp */
318
-
319
- #include "Interaction.hpp"
320
-
321
-
322
-
323
- //--- コンストラクタ定義 ---//
324
-
325
- Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
326
-
327
- set(nn, sf, sd, sa, cf, cd);
328
-
329
- }
330
-
331
-
332
-
333
- //--- デストラクタ定義 ---//
334
-
335
- Interaction::~Interaction(){
336
-
337
- if(dis != NULL) delete [] dis;
338
-
339
- if(angle != NULL) delete [] angle;
340
-
341
- }
342
-
343
-
344
-
345
- //--- セッタ ---//
346
-
347
- void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
348
-
349
- n = nn;
350
-
351
- sep_force = sf;
352
-
353
- sep_dis = sd;
354
-
355
- sep_angle = sa;
356
-
357
- coh_force = cf;
358
-
359
- coh_dis = cd;
360
-
361
- }
362
-
363
-
364
-
365
- //--- 分離力計算 ---//
366
-
367
- double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
368
-
369
- double that_sum[2] = {};
370
-
371
- double that_count = 0;
372
-
373
- double that_ave[2] = {};
374
-
375
- double dv_sep[2] = {};
376
-
377
- double my_posx = posx[num];
378
-
379
- double my_posy = posy[num];
380
-
381
-
382
-
383
- //--- 初期化 ---//
384
-
385
- that_sum[0] = 0;
386
-
387
- that_sum[1] = 0;
388
-
389
- that_count = 0;
390
-
391
-
392
-
393
- // 個体間距離と角度の計算 //
394
-
395
- for(int j = 0; j < n; j++) {
396
-
397
- if(num == j) continue;
398
-
399
- if(is_seated) continue; // 着席した人は力の影響を受けない
400
-
401
- if(is_group == false) continue; // 合流していない人は分離力の影響を受けない
402
-
403
- // 個体間距離と角度を計算 //
404
-
405
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
406
-
407
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
408
-
409
-
410
-
411
- // 分離力の範囲内なら //
412
-
413
- if(dis[j] <= sep_dis && angle[j] <= sep_angle){
414
-
415
- // 範囲内の個体の座標を合計 //
416
-
417
- that_sum[0] += posx[j];
418
-
419
- that_sum[1] += posy[j];
420
-
421
- that_count += 1;
422
-
423
- }
424
-
425
- }
426
-
427
-
428
-
429
- // 範囲内の個体の平均座標 //
430
-
431
- if(that_count != 0){
432
-
433
- that_ave[0] = that_sum[0] / that_count;
434
-
435
- that_ave[1] = that_sum[1] / that_count;
436
-
437
-
438
-
439
- // 分離力 //
440
-
441
- dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
442
-
443
- dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
444
-
445
- }else{
446
-
447
- // 分離力 //
448
-
449
- dv_sep[0] = 0;
450
-
451
- dv_sep[1] = 0;
452
-
453
- }
454
-
455
-
456
-
457
- return dv_sep;
458
-
459
- }
460
-
461
-
462
-
463
- //--- 結合力計算 ---//
464
-
465
- double Interaction::*CalculateCohesion(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
466
-
467
- double that_sum[2] = {};
468
-
469
- double that_count = 0;
470
-
471
- double that_ave[2] = {};
472
-
473
- double dv_coh[2] = {};
474
-
475
- double dis = 0;
476
-
477
- double angle = 0;
478
-
479
- double my_posx = posx[num];
480
-
481
- double my_posy = posy[num];
482
-
483
-
484
-
485
- for(int k=0; k<friends_num; k++){
486
-
487
- if(friends[k] == -1) continue;
488
-
489
- dis = E_dis(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
490
-
491
- angle = E_angle(my_posx, posx[friends[k]], my_posy, posy[friends[k]]);
492
-
493
- if(dis >= coh_dis){
494
-
495
- that_sum[0] += posx[friends[k]];
496
-
497
- that_sum[1] += posy[friends[k]];
498
-
499
- that_count++;
500
-
501
- }
502
-
503
- }
504
-
505
-
506
-
507
- // 範囲内の個体の平均座標 //
508
-
509
- if(that_count != 0){
510
-
511
- that_ave[0] = that_sum[0] / that_count;
512
-
513
- that_ave[1] = that_sum[1] / that_count;
514
-
515
-
516
-
517
- // 結合力 //
518
-
519
- dv_coh[0] = coh_force * (that_ave[0] - my_posx); // that_sum[0][i]);
520
-
521
- dv_coh[1] = coh_force * (that_ave[1] - my_posy); // that_sum[0][i]);
522
-
523
- }else{
524
-
525
- // 結合力 //
526
-
527
- dv_coh[0] = 0;
528
-
529
- dv_coh[1] = 0;
530
-
531
- }
532
-
533
-
534
-
535
- return dv_coh;
536
-
537
- }
538
-
539
-
540
-
541
- //--- 一緒にいる人数の判定 ---//
542
-
543
- int Interaction::CountWithNum(const int num, const double posx[], const double posy[], const int friends_num, const int friends[]){
544
-
545
- double my_posx = posx[num];
546
-
547
- double my_posy = posy[num];
548
-
549
- int withNum = 0;
550
-
551
-
552
-
553
- for(int j=0; j<n; j++) {
554
-
555
- if(num == j) continue;
556
-
557
- // 個体間距離と角度を計算 //
558
-
559
- dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
560
-
561
- angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
562
-
563
- if(dis[j] <= coh_dis + friends_num+1){ // 範囲内にいれば
564
-
565
- for(int k=0; k<friends_num; k++){ // 友人リストに含まれていたら
566
-
567
- if(friends[k] == j) withNum++; // 合流人数
568
-
569
- }
570
-
571
- }
572
-
573
- }
574
-
575
-
576
-
577
- return withNum;
578
-
579
- }
580
-
581
- ```

5

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

2021/10/15 03:59

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -194,11 +194,13 @@
194
194
 
195
195
  ```C++
196
196
 
197
- #Interaction.hpp
197
+ /* Interaction.hpp */
198
-
198
+
199
- #ifdef __CLASS__INTERACTION
199
+ #ifndef __CLASS__INTERACTION
200
+
201
+
202
+
200
-
203
+ #include <cmath>
201
-
202
204
 
203
205
  #include <vector>
204
206
 
@@ -312,6 +314,8 @@
312
314
 
313
315
  ```C++
314
316
 
317
+ /* Interaction.cpp */
318
+
315
319
  #include "Interaction.hpp"
316
320
 
317
321
 

4

実行環境を記載しました

2021/10/15 03:18

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -30,10 +30,6 @@
30
30
 
31
31
  /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 Interaction.cpp
32
32
 
33
- グラフの描画をするために色々使っています。
34
-
35
- このクラスを作る以前は問題なくコンパイルできていました。
36
-
37
33
 
38
34
 
39
35
  ### 発生している問題・エラーメッセージ

3

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

2021/10/15 02:55

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  ・コンパイル
30
30
 
31
- /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
31
+ /opt/homebrew/opt/llvm/bin/clang++ -std=c++17 Interaction.cpp
32
32
 
33
33
  グラフの描画をするために色々使っています。
34
34
 

2

実行環境を記載しました

2021/10/14 16:47

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,30 @@
12
12
 
13
13
 
14
14
 
15
+ ### 実行環境
16
+
17
+ ・C++バージョン
18
+
19
+ Apple clang version 12.0.5 (clang-1205.0.22.9)
20
+
21
+ Target: arm64-apple-darwin20.3.0
22
+
23
+ Thread model: posix
24
+
25
+ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
26
+
27
+
28
+
29
+ ・コンパイル
30
+
31
+ /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
32
+
33
+ グラフの描画をするために色々使っています。
34
+
35
+ このクラスを作る以前は問題なくコンパイルできていました。
36
+
37
+
38
+
15
39
  ### 発生している問題・エラーメッセージ
16
40
 
17
41
 

1

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

2021/10/14 16:20

投稿

jagaimo0
jagaimo0

スコア33

test CHANGED
File without changes
test CHANGED
@@ -18,9 +18,151 @@
18
18
 
19
19
  ```
20
20
 
21
+ ./Interaction.cpp:4:1: error: use of undeclared identifier 'Interaction'
22
+
23
+ Interaction::Interaction(int nn, double sf, double sd, double sa, double cf, double cd){
24
+
25
+ ^
26
+
27
+ ./Interaction.cpp:9:1: error: use of undeclared identifier 'Interaction'
28
+
29
+ Interaction::~Interaction(){
30
+
31
+ ^
32
+
33
+ ./Interaction.cpp:15:6: error: use of undeclared identifier 'Interaction'
34
+
35
+ void Interaction::set(int nn, double sf, double sd, double sa, double cf, double cd){
36
+
37
+ ^
38
+
39
+ ./Interaction.cpp:25:8: error: use of undeclared identifier 'Interaction'
40
+
41
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
42
+
43
+ ^
44
+
45
+ ./Interaction.cpp:39:22: error: use of undeclared identifier 'n'
46
+
47
+ for(int j = 0; j < n; j++) {
48
+
49
+ ^
50
+
51
+ ./Interaction.cpp:41:8: error: use of undeclared identifier 'is_seated'; did you mean 'is_seat'?
52
+
53
+ if(is_seated) continue; // 着席した人は力の影響を受けない
54
+
55
+ ^~~~~~~~~
56
+
57
+ is_seat
58
+
59
+ ./Interaction.cpp:25:110: note: 'is_seat' declared here
60
+
61
+ double Interaction::*CalculateSeparation(const int num, const double posx[], const double posy[], const bool is_seat, const bool is_group){
62
+
63
+ ^
64
+
65
+ ./Interaction.cpp:44:5: error: use of undeclared identifier 'dis'; did you mean 'div'?
66
+
67
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
68
+
69
+ ^~~
70
+
71
+ div
72
+
73
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
74
+
75
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
76
+
77
+ ^
78
+
79
+ In file included from classroomExit1.cpp:12:
80
+
81
+ ./Interaction.cpp:44:5: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
82
+
83
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
84
+
85
+ ^~~
86
+
87
+ ./Interaction.cpp:44:14: error: use of undeclared identifier 'E_dis'
88
+
89
+ dis[j] = E_dis(my_posx, posx[j], my_posy, posy[j]);
90
+
91
+ ^
92
+
93
+ ./Interaction.cpp:45:5: error: use of undeclared identifier 'angle'
94
+
95
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
96
+
97
+ ^
98
+
99
+ ./Interaction.cpp:45:16: error: use of undeclared identifier 'E_angle'
100
+
101
+ angle[j] = E_angle(my_posx, posx[j], my_posy, posy[j]);
102
+
103
+ ^
104
+
105
+ ./Interaction.cpp:48:8: error: use of undeclared identifier 'dis'; did you mean 'div'?
106
+
107
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
108
+
109
+ ^~~
110
+
111
+ div
112
+
113
+ /opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:146:42: note: 'div' declared here
114
+
115
+ inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
116
+
117
+ ^
118
+
119
+ In file included from classroomExit1.cpp:12:
120
+
121
+ ./Interaction.cpp:48:8: error: subscript of pointer to function type 'lldiv_t (long long, long long) noexcept'
122
+
123
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
124
+
125
+ ^~~
126
+
21
- use of undeclared identifier 'sep_dis'
127
+ ./Interaction.cpp:48:18: error: use of undeclared identifier 'sep_dis'
128
+
22
-
129
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
130
+
131
+ ^
132
+
133
+ ./Interaction.cpp:48:29: error: use of undeclared identifier 'angle'
134
+
135
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
136
+
137
+ ^
138
+
139
+ ./Interaction.cpp:48:41: error: use of undeclared identifier 'sep_angle'
140
+
141
+ if(dis[j] <= sep_dis && angle[j] <= sep_angle){
142
+
143
+ ^
144
+
145
+ ./Interaction.cpp:62:17: error: use of undeclared identifier 'sep_force'
146
+
147
+ dv_sep[0] = sep_force * (my_posx - that_ave[0]); // that_sum[0][i]);
148
+
149
+ ^
150
+
151
+ ./Interaction.cpp:63:17: error: use of undeclared identifier 'sep_force'
152
+
153
+ dv_sep[1] = sep_force * (my_posy - that_ave[1]); // that_sum[0][i]);
154
+
155
+ ^
156
+
157
+ ./Interaction.cpp:70:10: error: cannot initialize return object of type 'double' with an lvalue of type 'double [2]'
158
+
159
+ return dv_sep;
160
+
161
+ ^~~~~~
162
+
163
+ fatal error: too many errors emitted, stopping now [-ferror-limit=]
164
+
23
- など全ての変数やメソッドについて未定義のエラーメッセージが出ます
165
+ 20 errors generated.
24
166
 
25
167
  ```
26
168