On Wed, 2008-05-14 at 08:57 +0200, Thibault Genessay wrote: > Hi Jeremy > > > > Window* parent = wl->back()->getParent(); // wl is declared as 'const > > > WidgetList* wl' > > > > Was this the only line you needed to change? Were there others? :)> > > If it had only been as easy as modifying 1 line, I would have sent you > a patch rather than complaining :) > > I could not get the beast compiling because in so many places the same > programming logic is used. If I remove constness from somewhere, it > propagates upwards from caller to caller until everything becomes non > const ... > > I still don't understand how it can work with you guys ... Typical > things that seem wrong to me are: > > in src/UIObjectParent:54 > object_type* _getByName(const std::string& name) const { > for(ConstIterator i = begin(); i != end(); i++) { > if(i->valid() && i->get()->getName() == name) return > i->get(); > } > return 0; > } > A const method doing a const-iteration on a container cannot return a > non const pointer to an element of that container, can it ?
The prototype for ref_ptr::get looks like this: T* get() const { return _ptr; } It's a const method that returns a non-const pointer. I've done a bit of research, and this does appear to be something some compilers catch and some don't, so I'm not sure how OSG builds for any of us if we really adhering to some strict checking. In the above example, I imagine it works because while ref_ptr::get() returns a non-const pointer, the ConstIterator never calls a non-const method of the ref_ptr class. Perhaps a real C++ guru can shed some light here... > Somewhere else: > void Window::_setFocused(Widget* widget) { > [...] > } > > bool Window::setFocused(const Widget* widget) { > ConstIterator i = std::find(begin(), end(), widget); > _setFocused(i->get()); > } > // i->get() returns a const Widget* that cannot be passed as argument > to _setFocused(), can it ? > > I'm starting to feel strange, as if I had seen an alien and the FBI in > my garden and the government had told me that nothing had happened. > Nothing. So would have had my neighbours, making me feel alone and not > so sure that I had actually seen anything. :) I am as well. :) I'm going to install Fedora 9 (which will give me GCC4.2), and I'm going to google for some additional strict-checking options for GCC. Perhaps I can find a way to reproduce this and get it squashed... I've got VC++9 installed on my Windows partition, I've just never been able to get OSG to build at all there. However, there have been lots of threads recently on the subject, so perhaps now is the time to spend an afternoon doing it... At any rate, thanks for the info! > Regards > > Thibault > _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org