www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/31/00:52:01

From: John Clonts <johncc AT my-deja DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: c++ const definition in djgpp 2.95 problem
Date: Mon, 30 Aug 1999 21:30:24 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 70
Message-ID: <7qet5g$c2p$1@nnrp1.deja.com>
References: <37c18ffb DOT 1378453 AT news DOT kfunigraz DOT ac DOT at> <37cad280 DOT 1608331 AT news DOT kfunigraz DOT ac DOT at>
NNTP-Posting-Host: 204.254.32.135
X-Article-Creation-Date: Mon Aug 30 21:30:24 1999 GMT
X-Http-User-Agent: Mozilla/3.01Gold (Win95; I)
X-Http-Proxy: 1.0 x35.deja.com:80 (Squid/1.1.22) for client 204.254.32.135
X-MyDeja-Info: XMYDJUIDjohncc
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Doesnt this address what you're looking for (similar as posted by
elisnis):
#include <iostream>
using namespace std;

// typically would be in A.h
class A
{
  public:
  	static const int sz;
  	static const char nm[];
};

// typically would be in A.cpp
const int A::sz=7;
const char A::nm[sz]="012345";

// typical client code
int main()
{
	cout << A::sz << endl;
	cout << sizeof( A::nm) / sizeof( A::nm[0]) << endl;
	cout << A::nm << endl;
}

Cheers,
John

In article <37cad280 DOT 1608331 AT news DOT kfunigraz DOT ac DOT at>,
  remove_this_mimo AT restoel DOT net_and_this (mimo) wrote:
> first of all thanks for your replies. i am afraid i didn't explain my
> problem and aim exactly enough - as a matter of fact i only found out
> today while reading the replies waht my aim really was.
> according to this one c++ reference i used to read this way of
> defining constants was meant to replace c-style-macros (#define). in
> version 2.81 it was possibly to define constants this way.
> the positive effect was that the constants were parsed by the
> prerpocessor (think so...) means that they were treated more or less
> like c-macros. at the same time they were "clean" and free from
> typical c problems. that's one reason why i don't want to define
> anything in the global scope as someone proposed. namespaces were not
> implemented in version 2.81 (could anybody could give me an example of
> how to use them?).
> the other solution - using static member constants - differs from the
> stated aim. defining a constant this way results in having more class
> mebers than before (again think so...), means that static members are
> simply not the same as this precompiler-"trick".
> to make it clear an example:
>
> class c{
> 	static const int ciSize;
> 	static const apszString[ciSize];
> };
>
> this simply cannot be done with static members since at the time when
> the precompiler (??) reaches the second const it doesn't know the
> value of ciSize. i am rather sure that this is also the reason for the
> internal compiler error, which could be avoided if it were still
> possible to define consts the way i used to do.
> maybe there is another workaround - thanks in advance.
>
> cheers
>
> mimo
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019