public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: hash_map error: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers
@ 2005-11-05  1:25 Ricardo Fodra
  2005-11-05  1:52 ` Alex J. Dam
  0 siblings, 1 reply; 4+ messages in thread
From: Ricardo Fodra @ 2005-11-05  1:25 UTC (permalink / raw)
  To: gcc-help

Having a similar problem here:

  std::set<Person>* _family
  ...
  set<Person>::reverse_iterator iter =
_family->rbegin();
  ++iter;
> iter->setName(NULL);

error: passing `const Person' as `this' argument of
`void Person::setName(char*)' discards qualifiers

Why is the compiler thinking *iter is a "const
Person"? _family is not const and I'm not using a
const_reverse_iterator, although there are some
const_iterator in other parts of the code.

For now I'll just cast the const Person to a Person:

((Person*)(&(*iter)))->setName(NULL);

But I'd like to know how to fix this.

    Ricardo, Brazil.


	



	
		
_______________________________________________________ 
Yahoo! Acesso Grátis: Internet rápida e grátis. 
Instale o discador agora!
http://br.acesso.yahoo.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread
* hash_map error: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers  passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers
@ 2003-05-13 14:13 buggy
  2003-05-13 18:05 ` LLeweLLyn Reese
  0 siblings, 1 reply; 4+ messages in thread
From: buggy @ 2003-05-13 14:13 UTC (permalink / raw)
  To: gcc-help

Have you ever seen this error?,

 it means that I pass a pointer to a constant object out of it's protected context. Yes I cast it down to a normal pointer indeed. The pointer is actually casted to an integer. I'm keeping a hash of memory adresses with 
the adresses of kopies of the objects these adresses refer too. So I do not alter this const pointer. Here is the code:

//hash function object for the Mem_hash
class int_adr
{public:
const size_t operator()(const Port* const a)
    {  int i;
     /*haha, fooled ya*/   here is the fooling part that actually works on other compilers
      const Port * const s= a;//(Port *)a;
      i=(int)s;
     return i;
    }
};

//hash of memory adresses
typedef std::hash_map< const Port *, Port *, int_adr , equal_to <const Port * > > Mem_hash;

all these const identifiers are required by hash_map, the non-standard gnu stl-extension.

I don't wnat to change code that works with other compilers I need some compiler option or something to disable the error.

error mess:

gcc  -g -c -I/sw/pkg/gcc-2.95.2/include/g++-3  -I./loki main.cpp
stl_hashtable.h: In method `size_t hashtable<pair<const lambda_calculus::Port *const,lambda_calculus::Port *>,const lambda_calculus::Port *,lambda_calculus::int_adr,_Select1st<pair<const lambda_calculus::Port 
*const,lambda_calculus::Port *> >,equal_to<const lambda_calculus::Port *>,allocator<lambda_calculus::Port *> >::_M_bkt_num_key(const lambda_calculus::Port *const &, unsigned int) const':

stl_hashtable.h:536:   instantiated from `hashtable<pair<const lambda_calculus::Port *const,lambda_calculus::Port *>,const lambda_calculus::Port *,lambda_calculus::int_adr,_Select1st<pair<const 
lambda_calculus::Port *const,lambda_calculus::Port *> >,equal_to<const lambda_calculus::Port *>,allocator<lambda_calculus::Port *> >::_M_bkt_num(const pair<const lambda_calculus::Port 
*const,lambda_calculus::Port *> &, unsigned int) const'

stl_hashtable.h:930:   instantiated from `hashtable<pair<const lambda_calculus::Port *const,lambda_calculus::Port *>,const lambda_calculus::Port *,lambda_calculus::int_adr,_Select1st<pair<const 
lambda_calculus::Port *const,lambda_calculus::Port *> >,equal_to<const lambda_calculus::Port *>,allocator<lambda_calculus::Port *> >::resize(unsigned int)'

stl_hashtable.h:744:   instantiated from `hashtable<pair<const lambda_calculus::Port *const,lambda_calculus::Port *>,const lambda_calculus::Port *,lambda_calculus::int_adr,_Select1st<pair<const 
lambda_calculus::Port *const,lambda_calculus::Port *> >,equal_to<const lambda_calculus::Port *>,allocator<lambda_calculus::Port *> >::find_or_insert(const pair<const lambda_calculus::Port 
*const,lambda_calculus::Port *> &)'

stl_hash_map.h:181:   instantiated from here

stl_hashtable.h:531: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers
make: *** [main.o] Error 1

if you do got an idea please respond to buggy@hetnet.nl or to the list

thanks

ali


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-11-05  1:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-05  1:25 hash_map error: passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers passing `const lambda_calculus::int_adr' as `this' argument of `const size_t lambda_calculus::int_adr::operator ()(const lambda_calculus::Port *)' discards qualifiers Ricardo Fodra
2005-11-05  1:52 ` Alex J. Dam
  -- strict thread matches above, loose matches on Subject: below --
2003-05-13 14:13 buggy
2003-05-13 18:05 ` LLeweLLyn Reese

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).