Path: utzoo!attcan!uunet!mcsun!ukc!dcl-cs!aber-cs!athene!pcg From: pcg@cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.lang.c++ Subject: Re: Constant member variables in TC++ Message-ID: Date: 12 Nov 90 17:25:40 GMT References: Sender: pcg@aber-cs.UUCP Organization: Coleg Prifysgol Cymru Lines: 22 Nntp-Posting-Host: odin In-reply-to: ahuttune@niksula.hut.fi's message of 11 Nov 90 17:07:21 GMT On 11 Nov 90 17:07:21 GMT, ahuttune@niksula.hut.fi (Ari Juhani Huttunen) said: ahuttune> class X { ahuttune> const int const_int; ahuttune> }; ahuttune> Gives a warning: constant field not initialized. Perfectly correct. If you had RTFM with care, it would have emerged that it is now possible to initialize data members in the cosntructor, and that indeed this is the recommended way of doing so, and even more relevant, it is the only way to initialize constant non static data members. I do not like the ad-hoc rules for constructors like this, but such is the language. Rewrite your exmaple as: struct s { const int c; s(value) : c(value) {}; }; -- Piercarlo Grandi | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk