構造体の配列を別の構造体に動的に割り当てようとしています。ここにコードセグメントがあります
構文エラーは発生しませんが、str1を入力しようとするとセグメンテーション違反が発生します
誰かがセグメンテーション違反がある理由と、そのような状況で動的割り当てのメモリで何が起こるかを説明できますか
struct A {
string str1;
string str2;
}
struct B {
int count;
A* A_array;
}
void GetB (B** b)
{
*b = (B*) malloc(1*sizeof(B));
cout << "Enter count";
cin >> (**b).count;
(**b).A_array = (A*) malloc((**b).count*sizeof(A));
cout << "Enter str1";
cin >> (**b).A_array[0].str1;
cout << "Enter str2";
cin >> (**b).A_array[0].str2;
}
int main(){
B* b;
GetB(&b);
}