Re: [sigc] function of const object as slot
- From: Ulrich Eckhardt <eckhardt satorlaser com>
- To: libsigc-list gnome org
- Subject: Re: [sigc] function of const object as slot
- Date: Thu, 25 Aug 2005 09:56:25 +0200
Roel Vanhout wrote:
> The program below doesn't compile (at least on MSVC, the error is:
Naming a compiler without a version is almost meaningless. Also it would be
nice to know that you're using sigc++ 1.x. ;)
> error C2440:
> 'initializing' : cannot convert from 'const Foo' to 'Foo &'
> Conversion loses qualifiers
> see reference to
> function template instantiation
> 'SigC::Slot0<R>
> SigC::slot<std::string,const Foo,Foo>(O1 &,R (__thiscall Foo::* )(void)
> const)' being compiled
> with
> [
> R=std::string,
> O1=const Foo
> ]
> )
>
> How can I connect to a slot of a const object?
You can't. The point is that connecting a SigC::Object is a mutating
operation on the SigC::Object underneath - your connection is registered
there, so it can be automatically disconnected when the SigC::Object is
destroyed.
> I've tried putting
> 'const' just about everywhere I could imagine but no change apart from
> other error messages :) It compiles ok when I don't make the object 'f'
> const. Is it possible at all?
Ideas:
- Use const_cast, but that invokes UB when the object is a constant, i.e. if
it isn't just that you only have a const reference to it.
- Use SigC::class_slot, but then you loose the automatic disconnecting and
need to implement that manually - sometimes the automatic one doesn't work
that good anyway so it might not be a problem.
- Don't use a const object.
Uli
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]