From: Claudio Bley <bley@CS.uni-magdeburg.de>
To: gcc-help@gcc.gnu.org
Subject: Re: Inherited member( void )const - const to be or not to be
Date: Tue, 21 Sep 2004 13:34:00 -0000 [thread overview]
Message-ID: <20040921133438.GA1983@connect3.urz.uni-magdeburg.de> (raw)
In-Reply-To: <chheqb$k1i$1@sea.gmane.org>
On Mon, Sep 06, 2004 at 12:40:10PM +0200, SVisor wrote:
> Hi,
Hi.
> If this is wrong list, please point me to a better one.
>
> I have following code. If CONST (as described in code) is defined it
> will not compile (unless I do a C cast to CProvider* in
> CInherited::getProvider(void)const). *I* claim that it should compile
> even if CONST is defined. As the "const" only tells the compiler that
> the function will not change any members of the class, it says nothing
> about the return value. GCC 3.4.1 20040625 wants to see "this" as
> constant in the function.
>
> What is your opinion?
>
> Am I getting myself into trouble with the CInherited class if I use C
> cast (with C++ static/dynamic_cast it fails to compile) to make it compile?
>
> virtual CProvider* getProvider( void )CONST{ return this; }
This is forbidden. You can't assign a constant pointer (and "this" is const
in the body of that function) to a non-const pointer:
const int *pc;
int *p;
p = pc;
*p = 5;
next prev parent reply other threads:[~2004-09-21 13:34 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
2004-09-07 16:35 ` SVisor
2004-09-07 17:10 ` Eljay Love-Jensen
2004-09-21 13:34 ` Claudio Bley [this message]
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=20040921133438.GA1983@connect3.urz.uni-magdeburg.de \
--to=bley@cs.uni-magdeburg.de \
--cc=gcc-help@gcc.gnu.org \
/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).