[sigc] =?windows-1252?q?Compile_error=3A_invalid_initialization_o?= =?windows-1252?q?f_non-const_reference_of_type_=91some=5Fslot=26=92_from_?= =?windows-1252?q?a_temporary_of_type_=2E=2E=2E?=



Hello,

I am having problem with compilation of the following code:

class ExampleClass {
public:
        int f (int i, double d, char c);
        int g (int i, double d, char c, char * s);
};

int ExampleClass::f (int i, double d, char c) {
        std::cout << "Executing ExampleClass::f." << std::endl;
        return (0);
}

int ExampleClass::g (int i, double d, char c, char * s) {
        std::cout << "Executing ExampleClass::g." << std::endl;
        return (0);
}

typedef sigc::slot<int, int, double, char, char *> gslot;

int bar (gslot & gs) { // The argument is a reference
        std::cout << "Executing bar." << std::endl;
        gs(0, 1.0, 'c', "hello");
        return (0);
}

int bar2 (gslot gs) { // The reference is missing here
        std::cout << "Executing bar2." << std::endl;
        gs(0, 1.0, 'c', "hello");
        return (0);
}

int foo () {
        ExampleClass ec;
        gslot intermediate = sigc::hide(sigc::mem_fun(ec, &ExampleClass::f));
        bar(intermediate); // works
        bar(sigc::hide(sigc::mem_fun(ec, &ExampleClass::f))); // <-- COMPILE ERROR
        bar2(sigc::hide(sigc::mem_fun(ec, &ExampleClass::f))); // works
        return (0);
}

On my system with:

gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.3)
sigc++-2.0 version 2.2.3

I get this compile error:

error: invalid initialization of non-const reference of type ‘gslot&’ from a temporary of type ‘sigc::hide_functor<-0x00000000000000001, sigc::bound_mem_functor3<int, ExampleClass, int, double, char> >’
error: in passing argument 1 of ‘int bar(gslot&)’

This is interesting, because when I use an intermediate variable of the type sigc::slot to which I at first assign the created functor, then the parameter is passed successfully. Also, when I use a function (bar2) which is not taking a reference to sigc::slot, but just a sigc::slot as a parameter, then I am able to call it with the created functor directly.

I don't really understand this behaviour. What is the difference between calls to bar and bar2? Why is it not possible to initialize a parameter of type 'reference to sigc::slot' with a functor returned by sigc::hide directly? Why it is necessary to use intermediate sigc::slot? Should not be such a conversion automatic?

Thank you very much!


What can you do with the new Windows Live? Find out


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