Initializer for an array of pointers to arrays of strings

S

Steve

I want an initializer for an array of pointers to arrays of strings.

So I can do something like this:

const char* t1[] = { "a", "b", "c", 0 };
const char* t2[] = { "p", "q", 0 };
const char* t3[] = { "w", "x", "y", "z", 0 };
const char* const* test[] = { t1, t2, t3, 0 };

I was wondering whether the is a more elegant way of writing such an
initializer, one that does away with all the redundant names t1, t2, etc.

Many thanks
Steve
 
V

Victor Bazarov

Steve said:
I want an initializer for an array of pointers to arrays of strings.

So I can do something like this:

const char* t1[] = { "a", "b", "c", 0 };
const char* t2[] = { "p", "q", 0 };
const char* t3[] = { "w", "x", "y", "z", 0 };
const char* const* test[] = { t1, t2, t3, 0 };

I was wondering whether the is a more elegant way of writing such an
initializer, one that does away with all the redundant names t1, t2, etc.

Why do you say that they are redundant? If you want a pointer to
an array, you gotta have the array first. The only way to have
an array in C++ is to define one. That's what you need the tX for.
There are no "array literals" in C++.

V
 

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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top