RE: [sigc] function of const object as slot



That's quite normal since signal::connect is not a const function. One solution is to make the signal object mutable.



-----Message d'origine-----
De : Roel Vanhout [mailto:roel riks nl] 
Envoyé : mercredi 24 août 2005 12:37
À : libsigc-list gnome org
Objet : [sigc] function of const object as slot

Hi,

The program below doesn't compile (at least on MSVC, the error is:

Compiling...
constsigslot2.cpp
c:\Users\roel\ThirdParty\sigc++\object_slot.h(84) : error C2440: 
'initializing' : cannot convert from 'const Foo' to 'Foo &'
         Conversion loses qualifiers
         c:\test\constsigslot2\constsigslot2.cpp(25) : 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? 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? Thanks.

cheers,

roel




#include <string>
#include <sigc++/sigc++.h>

class Foo : public SigC::Object
{
public:
	std::string Bar() const
	{
		return "Bleh";
	}
};

int main(int argc, char* argv[])
{
	const Foo f;

	SigC::Signal0<std::string> signal;

	signal.connect(SigC::slot<std::string>(f, &Foo::Bar));

	std::cout << signal() << std::endl;

	return 0;
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]