を使用する場合、私はこのセグメンテーション障害:11ワンセグ障害の原因を見つけるために、GDBを用いて動的3Dアレイパラメータ
Program received signal SIGSEGV, Segmentation fault.
0x00000001000082bf in matchCounters (input=..., size=5,
valid_entries=0x100020cd0 <VALID_REGIONS>, nums=0x7fff5fbff460,
counters=0x100020588 <VTT for std::__1::basic_ifstream<char, std::__1::char_traits<char> >+8>) at akh70P3.cpp:524
524 cout << "counters[4][1] = " << counters[4][1] << endl;
メイン()
double *** all_counters;
generateCounters(all_counters);
matchCounters(/*some more parameters here*/ all_counters[0]);
matchCounters()
を得ますここでカウンタにアクセスすると、セグメント化エラーが発生します。11
void matchCounters(/*some more parameters here*/ double ** counters) {
//this causes segmentation fault 11
cout << "counters[4][1] = " << counters[4][1] << endl;
}
ここでは、カウンタにアクセス
generateCounters()
は
void generateCounters(double *** all_counters) {
all_counters = new double ** [2];
//region counters
all_counters[0] = new double * [VALID_REGIONS_SIZE];
//move kind counters
all_counters[1] = new double * [VALID_MOVE_TYPES_SIZE];
for(int i = 0; i < VALID_REGIONS_SIZE; i++) {
all_counters[0][i] = new double [CATEGORIES];
}
for(int i = 0; i < VALID_MOVE_TYPES_SIZE; i++) {
all_counters[1][i] = new double [CATEGORIES];
}
//this works just fine! why?
cout << "all_counters[0][4][1] = " << all_counters[0][4][1] << endl;
}
'generateCounters'では、 'all_counters ='の最初の行はその関数の* caller *に何も意味しません。あなたはローカル変数を変更するだけで、最終的には呼び出し元のポインタは変更されません。これには、何百もの重複した質問があります。[** this ** one](http://stackoverflow.com/questions/35330331/trying-to-dynamically-allocate-a-parent-pointer-to- a-child-inside-a-function-is) – WhozCraig