This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Can't invoke a non-const method on objects iterated from a std::set


Hi,
   if I define a set of objects and try to invoke a
non-const method on each of them while iterating the
set, I get a compilation error.  The gcc compiler
complains that I try to invoke a non-constant method
on a const object.  You can see that in a sample
program as attachment.

My gcc is of version 3.3.2 on Mandrake 10.0

Thanks in advance.

__________________________________________________________
Lèche-vitrine ou lèche-écran ?
magasinage.yahoo.ca
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>
#include <set>

using namespace std;

struct Toto {
	Toto(int i_key) : m_is_visible(false), m_key(i_key) {}
	Toto(const Toto& i_other) : m_is_visible(i_other.m_is_visible), m_key(i_other.m_key) {}
	Toto& operator=(const Toto& i_other) 
	{ 
		m_is_visible = i_other.m_is_visible;  
		m_key = i_other.m_key;
		return *this;
	}
	bool operator < (const Toto& i_other) 
	{ 
		return m_key < i_other.m_key;
	}

	void setVisibility(bool is_visible) {m_is_visible = is_visible;}
	bool m_is_visible;
	int m_key;
};
	

int main(int argc, char *argv[])
{
	set<Toto> totos;
	totos.insert(Toto(0));
	totos.begin()->setVisibility(true);
	
	cout << "Hello, world!" << endl;
	
	return EXIT_SUCCESS;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]