The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Array with const size in a class?
Discuss Array with const size in a class? in the C Programming forum on Dev Shed. Array with const size in a class? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 25th, 2006, 12:00 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58
Time spent in forums: 6 h 1 m 33 sec
Reputation Power: 10
|
|
|
Array with const size in a class?
Hi, I seem to be having a bit of trouble making a const accessible when declaring arrays in the same class. Is there any way to do this?
This code:
Code:
class GAME {
// blah blah
const int MAX_BUILDING_TYPES;
BUILDING_TYPE * building_types[MAX_BUILDING_TYPES];
}
... Doesn't seem to work. Assumably this is because the consts don't get initialised until the constructor line in the .cpp file, but this seems like the only way to do it.
The error I get is an odd one..
Quote: | 'GAME::MAX_BUILDING_TYPES' : member from enclosing class is not a type name, static, or enumerator |
Any ideas?
Thanks,
Kris
|

October 25th, 2006, 12:31 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Declare it like this:
Code:
class GAME {
// blah blah
static const int MAX_BUILDING_TYPES = 5;
BUILDING_TYPE * building_types[MAX_BUILDING_TYPES];
};
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

October 25th, 2006, 12:35 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58
Time spent in forums: 6 h 1 m 33 sec
Reputation Power: 10
|
|
Ahh. I actually tried that before, and got an error (C2258), but it seems like that's actually an issue with the compiler (I thought my code was just wrong).
Looks like I'm going to have to use this workaround:
Code:
enum { MAX_BUILDING_TYPES = 100; }
Silly MSVC :P
Thanks!
|

October 25th, 2006, 05:32 PM
|
|
|
Quote: | Originally Posted by Kris_A Silly MSVC | Is this MSVC 6? I thought .NET was standards compliant.
|

October 26th, 2006, 04:50 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58
Time spent in forums: 6 h 1 m 33 sec
Reputation Power: 10
|
|
|
Yep, it's 6. I don't really like the whole look and feel of .net so I don't bother with it.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|