www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/05/02:19:19

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Victor Bazarov" <vAbazarov AT dAnai DOT com>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++,alt.comp.lang.learn.c-c++
References: <3C0CCEE3 DOT A2D60376 AT bigfoot DOT com> <3C0CD55F DOT B04E8089 AT gascad DOT at> <3C0CD695 DOT 7F408020 AT bigfoot DOT com> <3C0CF679 DOT D0A24FB8 AT gascad DOT at> <3C0DB9D0 DOT 6217E7AD AT bigfoot DOT com>
Subject: Re: Passing 'const' as 'this' discards qualifiers
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <WgjP7.548$cH6.58104@rwcrnsc52>
Date: Wed, 05 Dec 2001 06:37:42 GMT
NNTP-Posting-Host: 204.127.202.211
X-Complaints-To: abuse AT attbi DOT com
X-Trace: rwcrnsc52 1007534262 204.127.202.211 (Wed, 05 Dec 2001 06:37:42 GMT)
NNTP-Posting-Date: Wed, 05 Dec 2001 06:37:42 GMT
Organization: AT&T Broadband
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Alex Vinokur" <alexvn AT bigfoot DOT com> wrote in message
news:3C0DB9D0 DOT 6217E7AD AT bigfoot DOT com...
>
>
> Karl Heinz Buchegger wrote:
>
> > Alex Vinokur wrote:
> > >
> > > Karl Heinz Buchegger wrote:
> > >
> > > > Alex Vinokur wrote:
> > > > >
> > > >
> > > > >   public:
> > > > >     bool operator() (AAA& ins1, AAA& ins2) const {return false;}
> > > >                                              *****
> > > >
> > >
> > > operator() on my program doesn't contain const :
> >
> > I know, but it should. At least this is what your compilers
> > error message means in plain english:
> >
> > > ttt.c:20: passing `const AAA' as `this' argument of `void AAA::foo1()'
> > > discards qualifiers
> >
> > means
> >
> > "You try to call a non-const function for a const object"
>
> Which object in my program is const?
>
>
> >
> >
> > Oh sorry. Just figured out that the error message doesn't talk
> > about the operator altogether. Instead you somewhere try
> > to call a function fool(). But the cure is the same. Make
> > foo() a const member function.
>
> Thanks. If foo1() is const a compiler doesn't detect error.
>
> But :
>   1. Why does the compiler detect an error if foo2() is non const?


My guess would be that since 'set' is an associative container,
dereferencing an iterator returns a constant object (each set
is an ordered collection, what good would non-const object ref
do if you could arbitrarily change it?)

>   2. What to do if foo2 must be non const?

Tough luck.  You are not supposed to change the object once they
have been inserted into an associative container.  That would
potentially change their relation and violate their ordering.

Victor
--
Please remove capital A's from my address when replying by mail


- Raw text -


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