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

回答編集履歴

1

2019/01/08 15:14

投稿

yumetodo
yumetodo

スコア5852

answer CHANGED
@@ -1,2 +1,38 @@
1
1
  そもそも論new/deleteを使ってはいけません。そしてあなたが必要なのはおそらくstd::vectorです。
2
- [https://cpprefjp.github.io/reference/vector/vector.html](https://cpprefjp.github.io/reference/vector/vector.html)
2
+ [https://cpprefjp.github.io/reference/vector/vector.html](https://cpprefjp.github.io/reference/vector/vector.html)
3
+
4
+ 完全なコードが無いので、適当にリファクタリングしつつ書き換えたのが下です。`Complex`とかいう謎の型も知らんのでとりあえず`std::complex<float>`のエイリアスにしています。`new`しているのは意味不明だったので単に配列にしています。
5
+
6
+ ```cpp
7
+ constexpr int LOOP1 = 10;
8
+ constexpr int LOOP2 = 15;
9
+ constexpr int L = 5;
10
+ #include <complex>
11
+ #include <iostream>
12
+ using Complex = std::complex<float>;
13
+ void funcA(Complex *in, Complex *pn, int L, int loop2){
14
+ //ここでpn配列の値を決める
15
+ for(int i=0;i<L;i++){
16
+ in[i] *= pn[loop2];
17
+ }
18
+ }
19
+ int main(void){
20
+ Complex pn[LOOP2];
21
+ Complex in[L];
22
+ for(int loop1=0;loop1<LOOP1;loop1++){
23
+ for(int loop2=0;loop2<LOOP2;loop2++){
24
+ funcA(in, pn, L, loop2);
25
+ }
26
+ }
27
+ for(auto& p : pn) std::cout << p << std::endl;
28
+ for(auto& i : in) std::cout << i << std::endl;
29
+ }
30
+ ```
31
+
32
+ 実行結果は
33
+
34
+ [https://wandbox.org/permlink/iiE6kkG0dtJIGpqi](https://wandbox.org/permlink/iiE6kkG0dtJIGpqi)
35
+
36
+ です。特に状況は再現できません。
37
+
38
+ ところで、pnが0のまま演算を進めても全部0のままでは?という思いです。