I want to initialize an array of std::string
pointers of size that i get from a constructor. Also, i want to do the same for two int
arrays but the code below doesn't compile:
class MyQuickInitArray
{
public:
MyQuickInitArray(int size)
{
if(size <= 0)
{
throw new std::exception;
}
_size = size;
_counter = 0;
A = new std::string[size];
B = new int[size];
C = new int[size];
}
std::string& operator[](int j) {
if(j > _size)
{
throw std::out_of_range("out of range");
}
if(((B[j]<0) || (B[j]>=_counter)) || (C[B[j]]!=j))
{
// A[j] points to junk
_counter++;
A[j] = new std::string;
B[j] = _counter-1;
C[_counter-1] = j;
return A[j];
}
// the cell was instantiated before
return A[j];
}
~MyQuickInitArray(){};
private:
std::string* A[];
int B[];
int C[];
int _size;
int _counter;
};
How can i properly declare an array of size that i get from a ctor?
EDIT:
The error that occurs is:
incompatible types in assignment of ‘std::string* {aka std::basic_string<char>*}’ to ‘std::string* [0]
And for the int
arrays:
incompatible types in assignment of ‘int*’ to ‘int [0]’