473,772 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to define class final constants?

I defines FileLogConstant class as following.

class FileLogConstant
{
public:
static const INT32 REGISTER_LOGGER ;

static const INT32 REGISTER_METHOD ;

static const INT32 MAX_LOGGER_COUN T;

static const INT32 MAX_LOGGER_METH OD_COUNT;

static const INT32 MAX_LOG_MESG_CO UNT;

static const INT32 MAX_REG_COUNT;

static const INT32 MAX_FILE_LENGTH ;
};

/////////////////////////////////////////////BLOCK
DEF//////////////////////////////////////////////////////////////

const INT32 FileLogConstant ::REGISTER_LOGG ER = 0x00;

const INT32 FileLogConstant ::REGISTER_METH OD = 0x01;

const INT32 FileLogConstant ::MAX_LOGGER_CO UNT = 64;

const INT32 FileLogConstant ::MAX_LOGGER_ME THOD_COUNT = 128;

const INT32 FileLogConstant ::MAX_LOG_MESG_ COUNT = 128;

const INT32 FileLogConstant ::MAX_REG_COUNT = 16;

const INT32 FileLogConstant ::MAX_FILE_LENG TH = 4 + 4 +
FileLogConstant ::MAX_LOGGER_CO UNT *
(16 + 4 + 64 * FileLogConstant ::MAX_LOGGER_ME THOD_COUNT) + 4 + 4 +
FileLogConstant ::MAX_LOG_MESG_ COUNT * (2 + 2 + 4 + 4 + 256) +
FileLogConstant ::MAX_REG_COUNT * (2 + 2 + 64);

/////////////////////////////////////////////////BLOCK
DEF////////////////////////////////////////////////////////////

class Foo
{
public:
char buffer[FileLogConstant ::MAX_FILE_LENG TH];
};

when BLOCK DEF is put in FileLogConstant .cpp file, the buffer
declaration of class Foo will be compiled with an error. While BLOCK
DEF is put in FileLogConstant .h file, the compiler will generate many
const FileLogConstant ::MAX_FILE_LENG TH already defined errors.

How to define class final constants?

Nov 28 '06
13 1978

Allen wrote:
No. It cannot be compiled by VC++ 6.0.
VC6 has a lot of problems with implementing the C++ standard correctly,
IOW its probably the compiler in this case that is letting you down.
I will test with gcc.
If it fails with gcc then again try a more recent version if possible,
but if it does fail then you probably have a quite old version of gcc.

regards
Andy Little

Nov 30 '06 #11

"kwikius дµÀ£º
"
Allen wrote:

VC6 has a lot of problems with implementing the C++ standard correctly,
IOW its probably the compiler in this case that is letting you down.
If it fails with gcc then again try a more recent version if possible,
but if it does fail then you probably have a quite old version of gcc.
When was the newest C++ standard put forward?
VC6 may be implement C++ standard before 1998.

Nov 30 '06 #12

Allen wrote:
"kwikius дµÀ£º
"
Allen wrote:

VC6 has a lot of problems with implementing the C++ standard correctly,
IOW its probably the compiler in this case that is letting you down.
If it fails with gcc then again try a more recent version if possible,
but if it does fail then you probably have a quite old version of gcc.

When was the newest C++ standard put forward?
VC6 may be implement C++ standard before 1998.
According to my copy of the C++ standard, BS ISO/IEC 14882 (the C++
standard) was ratified in 1997, however AFAIK Microsoft Borland and
others saw the potential of C++ for Windows development way before that
of course and so produced compilers predicting I guess what the
standard would be and also perhaps more importantly trying to keep
compatibility with their previous software. Also the C++ templates
specification was rushed into the standard quite late as far as I know,
which of course put existing compilers in a tricky position, IOW you
can't blame them for that and MSVC1.0 was my first C++ compiler which I
am really grateful to for introducing me to the language.

As I understand it the template specs were put in the standard without
anyone really having a working compiler that implemented them
correctly. It seems that Bjarne Stroustrup must have cast some sort of
spell over the Approval committee, which even he was surprised actually
worked if I remember from reading his book '"The design and evolution
of C++". So this is the sort of problem compiler writers faced at that
time.

Also I think that the ability to define static integral constants
inside the class definition was another late addition.

For the MS series both VC7.1 (not VC7.0) and VC8.0 do a good job of
implementing the current Standard.

As for gcc I curreently have gcc 4.0 , for earlier versions I am not so
sure, but a wild guess is to try to get a version after around gcc 3.3
or so.

And even in the latest compilers, if you look hard enough, you can find
something that is not correct.

That is part of the mystique of C++ FAICS. No one will ever truly
master it. And of course as soon as compilers get up to speed there
will be a new version of the standard and the whole rigmarole of non
conforming compilers will continue as usual :-)

regards
Andy Little

Nov 30 '06 #13

Allen wrote in message ...
/* """
"kwikius дµÀ£º
"
Allen wrote:

VC6 has a lot of problems with implementing the C++ standard correctly,
IOW its probably the compiler in this case that is letting you down.

If it fails with gcc then again try a more recent version if possible,
but if it does fail then you probably have a quite old version of gcc.
When was the newest C++ standard put forward?
VC6 may be implement C++ standard before 1998.

""" */

Ah ha, old compiler. Then maybe you can use the old hack:

class Allen{
enum { size = 1000 };
int i[size];
// .....
};

--
Bob R
POVrookie
Nov 30 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5562
by: codecraig | last post by:
Hi, I have a question about how to define constants. My directory structure looks like... C:\ --> abc.py --> utils --> __init__.py --> CustomThing.py
8
2558
by: John Ratliff | last post by:
Let's say I had a program which uses some constants. Would it be "better" to declare them like this: #ifndef __MY_HDR_FILE #define __MY_HDR_FILE #define STRING_CONST "some string..." #define INT_CONSTANT 4852 #endif
7
2487
by: Morgan Cheng | last post by:
Hi, In my program module, there are some Constants should be defined to be integer key value of std::map. In the module, methods of a few classes will return std::map containing value indexed by constant integer key value. I am wondering what is a good way to define these constants. 1) #define A = 0 #define B = 1 #define C = 2
4
51179
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be a wise idea to create a clsCommonApp and let all other classes to be derived from that class? and define all constants in that base class? Any other suggestions are more than welcome. (BTW this is not for one constant, I have multiple...
7
2563
by: Don Wash | last post by:
Hi There! I'm trying to define constants so that I can refer those constants from any page of my ASP.NET website. I know I can use <appSettings> in web.config XML file but I don't want to parse and read the whole XML document everytime a page is requested. In classic ASP, I used Include files and define constants using Const keyword so that every page that has been included the file can refer the constants.
1
2186
by: Kburge03 | last post by:
Hi!! I've been working on this assingment for class where I have to design and implement an application that displays two Die objects, a button, and a label. Every time the button is pushed, the following should happen: the two Die objects should be rolled, the face value of the two Die objects should be displayed and the label should display the sum of the two dice. I got so close so far, but now the gui won't even pop up with the driver...
5
2574
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so: const char *s = string_mapper<thetype>(); However I do not know the string to be associated with the type at compile time, and will need a way to set up the mapping, to be created at run time, possibly like so: void foo(char*...
6
1275
by: Charles D Hixson | last post by:
I'm trying to construct read-only variables at the class level. I've been unsuccessful. Any suggestions? Mixing @classmethod and @property doesn't appear to produce workable code. Ditto for mixing @classmethod and __getattr__. (The property approach compiles, but execution says that you can't execute properties.) I've got a rather large number of variables, so I don't want to define function accessors for each of them, and I...
7
2777
by: Chris Saunders | last post by:
I'm not very familiar with C#. I have a static class and would like to define some constants similarily to Math.PI. Could someone show me how to go about doing this. So far no luck searching. Regards Chris Saunders
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.