![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Help a C++ Idiot: I am trying to fill an array based on a switch statement.Ideally I would like to fill an array with different sets of strings as follows:
CPP / C++ / C Code:
I have tried using temporary arrays and copying them in but if you use the same one then the compiler whines about mulitple definitions. If you use separate ones it complains about some local variables not being initialsed by the end of the switch statement! I could initialse all of the temp arrays outside of the switch and then use another method to copy them one by one into the array, but is there a less ugly way to do it? I'm new to C++ but used to Java (where the answer would be items = temp; or items = new int[]{"blah","bloh"}; ). Can you make an anonimous array? Thanks very much, Psycop Last edited by dsmith : 13-Apr-2004 at 18:11.
|
|||
|
#2
|
|||
|
|||
|
Well it seems that if I use a horrible bunch of if statements the problem is circumvented. I should think this is because the compiler is not detecting the fact that the other case statements are unreachable (due to breaks). Stupid compiler (borland bcc55). Is this true for them all, and more generally is there a more elegant solution to this?
Chars. |
|
#3
|
||||
|
||||
|
Quote:
Are you going to modify the strings once you assign them to items? If not, define items as a pointer and load an address of the strings into the pointer: Code:
If you are going to change the strings, your job is much harder. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| switch statement | freedomJoe | C Programming Language | 0 | 27-Oct-2003 09:45 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The