I have:
class first{
private:
int *array;
public:
first(int x){
array = new int[x][10];
}
I want to call this class by:
first class1 = new first(10);
Why it doesn’t work ? How to inintialize array by size from constructor ??
Just this is enough:
newis for when you’re allocating a pointer.Furthermore, you have an incompatibility here:
arrayis anint*, butnew int[x][10]is a 2D array. I’m not sure which one you want.For the 1D array:
For the 2D array:
That said, you might be better off using
std::vector.Side Note: Since you have memory allocation in the constructor, you should also implement a destructor, copy-constructor, and copy-assignment operator.