Hello..
Im trying to make a way to have a dynamic array....
I was doing a test with global pointers and the heap. Would someone
tell me thy this doesn't compile:
#include <iostream>
using namespace std;
void Test();
int * ptr;
ptr = new int [3];
main(){
int * ptr;
ptr = new int [3];
ptr[2] = 1;
Test();
cout << ptr[3] << endl;
return 0;
}
void Test(){
delete[] ptr;
int * ptr;
ptr = new int [4];
ptr[3] = 10;
}
I get the error:
Test.cpp:7: error: expected constructor, destructor, or type conversion
before '=' token
Thanks alot
Im trying to make a way to have a dynamic array....
I was doing a test with global pointers and the heap. Would someone
tell me thy this doesn't compile:
#include <iostream>
using namespace std;
void Test();
int * ptr;
ptr = new int [3];
main(){
int * ptr;
ptr = new int [3];
ptr[2] = 1;
Test();
cout << ptr[3] << endl;
return 0;
}
void Test(){
delete[] ptr;
int * ptr;
ptr = new int [4];
ptr[3] = 10;
}
I get the error:
Test.cpp:7: error: expected constructor, destructor, or type conversion
before '=' token
Thanks alot
Comment