以下のコードを機能させるためにヒープの割り当てが必要な理由を知りたいのですが?
(nbこれは答えの拡張かもしれません: ポインタと代入)
例えば :
#include <iostream>
#include <fstream>
using namespace std;
int *array;
int main(){
array = int array[100];
}
コンパイラエラーを作成します
test.cpp:7:14: error: expected '(' for function-style cast or type construction
array = int array[100];
~~~ ^
1 error generated.
but = new int array[100]; 動作するようです。なぜ ?