public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eljay Love-Jensen <eljay@adobe.com>
To: svisor@lycos.com, gcc-help@gcc.gnu.org
Subject: Re: Inherited member( void )const - const to be or not to be
Date: Tue, 07 Sep 2004 12:58:00 -0000	[thread overview]
Message-ID: <6.1.2.0.2.20040907075501.01eafe30@iplan-mn.corp.adobe.com> (raw)
In-Reply-To: <chheqb$k1i$1@sea.gmane.org>

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

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();
}

  reply	other threads:[~2004-09-07 12:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-06 11:01 SVisor
2004-09-07 12:58 ` Eljay Love-Jensen [this message]
2004-09-07 16:35   ` SVisor
2004-09-07 17:10     ` Eljay Love-Jensen
2004-09-21 13:34 ` Claudio Bley
2004-09-21 13:41   ` Claudio Bley
2004-09-07 16:40 lrtaylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6.1.2.0.2.20040907075501.01eafe30@iplan-mn.corp.adobe.com \
    --to=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=svisor@lycos.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).