![]() |
|
#1
|
|||
|
|||
Help using const arrays in c++ classesI have looked all over the place for the answer. How do you handle const in c++ classes?
Here is my class. CPP / C++ / C Code:
If I declare the *suit and *face pointer arrays as data members in the class, I get an error about static const stuff. How should I go about this? I have no idea? |
|
#2
|
|||
|
|||
|
I guess, its because you have not initialized all the members in array "face". It is supposed to have 52 members strings, but you have initialized only 13.
If you are not sure in advance as to how many member array will have, you can have the following CPP / C++ / C Code:
This compiled fine for me. You can add member later as the array grows. Thanks, |
|
#3
|
|||
|
|||
|
Quote:
This is true, but my question is. How do you define a const array data member in the public: area of the class. As you see. If i want to define CPP / C++ / C Code:
CPP / C++ / C Code:
Also, for you solution for not defining the size of the array, so the array can grow. That won't work b/c the array is const and you can't edit a const. |
|
#4
|
|||
|
|||
This is how I want itThis is how I would like it, so I can't create an object of the class and access the data members in the class.
CPP / C++ / C Code:
This is the error I get Code:
I get the same error for 'face' |
|
#5
|
|||
|
|||
|
Sorry, but I do not know about C++ syntax. I thought it was just a syntax related problem with "const char**" which got solved when I complied as a simple C program.
Hang on there, someone else might reply to your post. Thanks, |
|
#6
|
|||
|
|||
Found solutionThis is what I was trying to accomplish and I have fixed the problem!
http://www-h.eng.cam.ac.uk/help/tpl/languages/C++/Thinking_in_C++/tic0111.html |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error - unresolved external symbol _WinMain | ap6118 | CPP / C++ Forum | 6 | 23-Mar-2005 22:46 |
| Help with const? | jheron | CPP / C++ Forum | 4 | 10-Mar-2005 20:24 |
| I need help implementing | kjc_13 | CPP / C++ Forum | 0 | 14-Feb-2005 16:00 |
| template comiling problems - need expert debugger! | crq | CPP / C++ Forum | 1 | 01-Feb-2005 21:26 |
| Error: (function) undeclared -first use of this function | crystalattice | CPP / C++ Forum | 6 | 01-Nov-2004 04:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The