From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23563 invoked by alias); 7 Sep 2004 12:58:34 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 23543 invoked from network); 7 Sep 2004 12:58:31 -0000 Received: from unknown (HELO psmtp.com) (12.158.35.213) by sourceware.org with SMTP; 7 Sep 2004 12:58:31 -0000 Received: from source ([192.150.22.7]) by exprod6ob3.obsmtp.com ([12.158.35.250]) with SMTP; Tue, 07 Sep 2004 05:58:31 PDT Received: from inner-relay-1.corp.adobe.com (inner-relay-1 [153.32.1.51]) by smtp-relay-7.sea.adobe.com (8.12.10/8.12.10) with ESMTP id i87CwUNf021095; Tue, 7 Sep 2004 05:58:30 -0700 (PDT) Received: from iplan-mn (iplan-mn.corp.adobe.com [130.248.25.5]) by inner-relay-1.corp.adobe.com (8.12.9/8.12.9) with ESMTP id i87CwUTk019876; Tue, 7 Sep 2004 05:58:30 -0700 (PDT) Received: from mn-eljay-a51m.adobe.com ([130.248.178.90]) by iplan-mn.corp.adobe.com (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0I3O00II69DGEY@iplan-mn.corp.adobe.com>; Tue, 07 Sep 2004 07:58:29 -0500 (CDT) Date: Tue, 07 Sep 2004 12:58:00 -0000 From: Eljay Love-Jensen Subject: Re: Inherited member( void )const - const to be or not to be In-reply-to: X-Sender: eljay@iplan-mn.corp.adobe.com To: svisor@lycos.com, gcc-help@gcc.gnu.org Message-id: <6.1.2.0.2.20040907075501.01eafe30@iplan-mn.corp.adobe.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT References: X-SW-Source: 2004-09/txt/msg00049.txt.bz2 Hi Jarmo, Don't use _CONST ... that's a reserved symbol. All symbols starting with underscore followed by a capital letter are reserved. All symbols with two underscores in a row anywhere are reserved. I've fixed your code, works now just fine. Compiled either way. BTW: using the -DCONST=const is preferred. So much so, that you should just have const in the code. Const correctness should be worked in from the beginning. HTH, --Eljay - - - - - - - - - // Compile #1: g++ -DCONST=const foo.cpp // Compile #2: g++ -DCONST= foo.cpp #include class CProvider { protected: const char* str; public: CProvider(const char* s) : str(s) { printf("CProvider(%s)\n",str); } void echo() CONST { printf("CProvider(%s)::echo()\n", str); } }; class CAbstract { public: CAbstract() { printf("CAbstract\n"); } virtual ~CAbstract() { } virtual CProvider CONST* getProvider() CONST = 0; }; class CAllocated : public CAbstract { protected: CProvider* ptr; public: CAllocated() { printf("CAllocated\n"); ptr = new CProvider("Allocated"); } virtual CProvider CONST* getProvider() CONST { return ptr; } }; class CInherited : public CAbstract, public CProvider { public: CInherited() : CProvider("Inherited") { printf("CInherited\n"); } virtual CProvider CONST* getProvider() CONST { return this; } }; int main() { CAllocated tmp1; CInherited tmp2; tmp1.getProvider()->echo(); tmp2.getProvider()->echo(); CAbstract* pTmp1 = &tmp1; CAbstract* pTmp2 = &tmp2; pTmp1->getProvider()->echo(); pTmp2->getProvider()->echo(); }