delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/31/19:40:30

From: horst DOT kraemer AT snafu DOT de (Horst Kraemer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: c++ const definition in djgpp 2.95 problem
Date: Tue, 31 Aug 1999 07:06:17 GMT
Organization: [Posted via] Interactive Networx
Message-ID: <37cb0274.9463438@news.snafu.de>
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: n243-180.berlin.snafu.de
X-Newsreader: Forte Free Agent 1.11/32.235
Lines: 48
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Mon, 30 Aug 1999 19:11:56 GMT,
remove_this_mimo AT restoel DOT net_and_this (mimo) wrote:

> 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.


What you say is a little bit confusing. I assume that you want this:


#include <iostream>

class C {
public:
  static const int ciSize=10;
  static const char apszString[ciSize];
};

const int C::ciSize; // no initialization here ! 
const char C::apszString[ciSize]="123456789";

int main() {
  cout << c::apszString << endl;
  return 0;
}


This is Standard C++ and gcc 2.95 and 2.8.1 do compile it correctly.


Regards
Horst

- Raw text -


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