Array of char pointers

fds

Joined
Jul 17, 2010
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top