I am trying to dynamically allocate a array inside a class. Came across a very weird thing. Please have look on this two piece of code and do tell me the difference.
class A{
public:
int n;
int *a;
a = new int [4];
~A(){delete []a;}
A(){}
}
Compiling with GCC produces the following error:
a does not a name type
But when I use:
class A{
public:
int n;
int *a = new int [4];
A(){}
~A(){ delete []a;}
}
It compiles