This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Funky static const errors.. anyone?


Funky static const errors.. anyone?

Postby wyrd » Jan 21, 2004 @ 7:08pm

wyrd
pm Member
 
Posts: 125
Joined: Jan 2, 2004 @ 10:19pm


Re: Funky static const errors.. anyone?

Postby Kzinti » Jan 21, 2004 @ 7:23pm

In VC 6 (and thus EVC 3 and 4), you can't declare static const member variables. The usual work around is to use enums:

class MyClass
{
enum
{
MY_CONSTANT = 100;
};

};

But then you lose type safety.

If it's uneeded in the header, then just declare it in the .cpp as a "local" static variable.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby wyrd » Jan 21, 2004 @ 7:25pm

Ah, okay. Well at least I know I wasn't going crazy. :) Thanks for the tip, enum seems like a slightly better alternative than #define (must.. not.. use.. globals).
wyrd
pm Member
 
Posts: 125
Joined: Jan 2, 2004 @ 10:19pm


Postby Pejo Software - Per » Jan 21, 2004 @ 7:34pm

Thierry are you sure?

I think the following will work:

class CGameWindow
{
static const DWORD DEFAULT_HEIGHT;
};

In cpp file:
const DWORD CGameWindow::DEFAULT_HEIGHT=100;
User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby Kzinti » Jan 21, 2004 @ 7:45pm

I don't think it does, but if it works then it not a constant anymore. It's a real variable.

I am sure though that you can't declare and initialize a static const member variable in the header file (before .NET) so that it get used as a constant.
Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby mlepage » Jan 21, 2004 @ 7:55pm

www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Pejo Software - Per » Jan 21, 2004 @ 8:00pm

User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby Kzinti » Jan 21, 2004 @ 8:03pm

Kzinti
pm Member
 
Posts: 3238
Joined: Jan 13, 2002 @ 5:23am


Postby wyrd » Jan 21, 2004 @ 8:09pm

wyrd
pm Member
 
Posts: 125
Joined: Jan 2, 2004 @ 10:19pm


Postby Pejo Software - Per » Jan 21, 2004 @ 8:16pm

User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby wyrd » Jan 21, 2004 @ 8:29pm

wyrd
pm Member
 
Posts: 125
Joined: Jan 2, 2004 @ 10:19pm


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron