C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2006, 12:00 PM
Kris_A Kris_A is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58 Kris_A User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old October 25th, 2006, 12:31 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,406 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 9 h 47 m 28 sec
Reputation Power: 4080
Declare it like this:
Code:
class GAME {
        // blah blah
        static const int MAX_BUILDING_TYPES = 5;
        BUILDING_TYPE * building_types[MAX_BUILDING_TYPES];
};
Comments on this post
Kris_A agrees!
__________________
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

Reply With Quote
  #3  
Old October 25th, 2006, 12:35 PM
Kris_A Kris_A is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58 Kris_A User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #4  
Old October 25th, 2006, 05:32 PM
Oler1s Oler1s is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2006
Posts: 2,270 Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level)Oler1s User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 15 h 34 m 57 sec
Reputation Power: 1735
Quote:
Originally Posted by Kris_A
Silly MSVC
Is this MSVC 6? I thought .NET was standards compliant.

Reply With Quote
  #5  
Old October 26th, 2006, 04:50 AM
Kris_A Kris_A is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58 Kris_A User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Array with const size in a class?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap