X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: Alex Vinokur Newsgroups: comp.os.msdos.djgpp,comp.lang.c++,alt.comp.lang.learn.c-c++ Subject: Re: Passing 'const' as 'this' discards qualifiers Date: Wed, 05 Dec 2001 08:08:17 +0200 Organization: Scopus Network Technologies Lines: 99 Message-ID: <3C0DB9D0.6217E7AD@bigfoot.com> 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> NNTP-Posting-Host: 62.90.123.5 Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1007532500 9541513 62.90.123.5 (16 [79865]) X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie 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? 2. What to do if foo2 must be non const? =============================================================== Windows98 gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp) compiled by GNU C version 2.95.3 20010315/djgpp (release). =============================================================== //------------- C++ Code : BEGIN ------------- #include class AAA; class less_AAA { public: bool operator()(AAA& ins1, AAA& ins2) {return false;} }; class AAA { public: void foo1 () const {}; void foo2 () {}; }; int main () { set::iterator iter; iter->foo1(); iter->foo2(); // Line#22 return 0; } //-------------- C++ Code : END -------------- //------------- Compiling : BEGIN ------------ ttt.c: In function `int main()': ttt.c:22: passing `const AAA' as `this' argument of `void AAA::foo2()' discards qualifiers //-------------- Compiling : END ------------- =========================== Alex Vinokur mailto:alexvn AT bigfoot DOT com mailto:alexvn AT dr DOT com http://up.to/alexvn http://go.to/alexv_math ===========================