Hi there,
I've just started to pick up C++. I've been trying to figure out what's wrong with the following code for a few hours. It probably is a simple and trivial error rooted in something I have understood wrong about the concepts of pointers and arrays in VC++ to which I'm new. So apologies and thanks in advance.
I'm trying to define an array of pointers (to hold a series of text) in the header file:
class ...
{
..
private:
char *array[];
}
and in the c++ file:
Constructor... or some other method
{
array = new char*[]; //Error line
}
I've tried a variety of the Error line and I get different error messages (all error C2440 which has something to do with incompatible types). If I change the line to:
char* array = new char[];
then it works fine. But this is a local and different declaration and am not even sure that is an array of chars.
So could you please tell me what is wrong here? I'd appreciate a little explanation as I'm sure I have misunderstood some sort of concept here.
Thank you very much for your time.
BTW, I know I can use some other types of ready-made arrays which make the job easier. I'm not writing anything special at the moment, I'm just trying to understand VC++ here and get the concepts.
And another question, when I'm trying to:
delete [] array;
I get "warning C4154: declaration of a array expression; conversion to pointer supplied." Why am I getting this here?
Thanks again. Looking forward to some enlightenment here
F
I've just started to pick up C++. I've been trying to figure out what's wrong with the following code for a few hours. It probably is a simple and trivial error rooted in something I have understood wrong about the concepts of pointers and arrays in VC++ to which I'm new. So apologies and thanks in advance.
I'm trying to define an array of pointers (to hold a series of text) in the header file:
class ...
{
..
private:
char *array[];
}
and in the c++ file:
Constructor... or some other method
{
array = new char*[]; //Error line
}
I've tried a variety of the Error line and I get different error messages (all error C2440 which has something to do with incompatible types). If I change the line to:
char* array = new char[];
then it works fine. But this is a local and different declaration and am not even sure that is an array of chars.
So could you please tell me what is wrong here? I'd appreciate a little explanation as I'm sure I have misunderstood some sort of concept here.
Thank you very much for your time.
BTW, I know I can use some other types of ready-made arrays which make the job easier. I'm not writing anything special at the moment, I'm just trying to understand VC++ here and get the concepts.
And another question, when I'm trying to:
delete [] array;
I get "warning C4154: declaration of a array expression; conversion to pointer supplied." Why am I getting this here?
Thanks again. Looking forward to some enlightenment here
F