开发者

compile error: no class template, too many initializers, no matching function

开发者 https://www.devze.com 2023-04-07 01:47 出处:网络
I haven\'t been able to remove compile errors using boost::signals. Any idea would be appreciated. Since I\'ve been porting a program that\'s written 2 years ago adjusting to the current environment,

I haven't been able to remove compile errors using boost::signals. Any idea would be appreciated.

Since I've been porting a program that's written 2 years ago adjusting to the current environment, I'm still new to boost::signals. The codes below are what I modified the original program to simplify for the question purpose.

I want a direct solution to my question. But besides that, because there are many questions regarding to boost::signals (but I've given up figuring out which one is the right/closest to my case), I'd give a vote to the ones that suggest in the answer area more proper titles of this question in order to make this a better archived question.

boostProve_Doc.h

#ifndef FC_H
#define FC_H

#include <vector>
#include "iostream"
#include "boost/signal.hpp"
typedef boost::signal<void()> PostUpdateSignal;
typedef PostUpdateSignal::slot_function_type PSlot;

class Doc {
public:
    Doc(uint width, uint height) {
        std::cout << "In constructor. width= " << width << ", height= "
                << height << std::endl;
    }
    ~Doc() {
        //Do ...
    }

    void connectPostUpdate(PSlot s) {
        sig.connect(s);
    }

protected:
    PostUpdateSignal sig;
};
#endif

boostProve_View.cpp:

#include <string>
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
#include <boost/bind.hpp>
#include <boostProve_Doc.h>

using namespace std;
class View {
public:
    View() {
        setupCrowd();
    }
    ~View() {
        //do something...
    }
private:
    Doc *crowd_;
    void setupCrowd() {
        crowd_->connectPostUpdate(&View::correctR);
    }
    void correctR() {
        // do something..
    }
};

int main(int argc, char** argv) {
    View c();
    return 0;
}

Error:

$ g++ boostProve_View.cpp -I . /usr/lib/libboost_signals.so
In file included from /usr/include/boost/function/detail/maybe_include.hpp:13,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
                 from /usr/include/boost/function.hpp:64,
                 from /usr/include/boost/thread/future.hpp:20,
                 from /usr/include/boost/thread.hpp:24,
                 from boostProve_View.cpp:3:
/usr/include/boost/function/function_template.hpp: In member function ‘void boost::function0<R>::assign_to(Functor) [with Functor = void (View::*)(), R = void]’:
/usr/include/boost/function/function_template.hpp:722:   instantiated from ‘boost::function0<R>::function0(Functor, typename boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with Functor = void (View::*)(), R = void]’
/usr/include/boost/function/function_template.hpp:1064:   instantiated from ‘boost::function<R()>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with Functor = void (View::*)(), R = void]’
boostProve_View.cpp:20:   instantiated from here
/usr/include/boost/function/function_template.hpp:903: error: no class template named ‘apply’ in ‘struct boost::detail::function::get_invoker0<boost::detail::function::member_ptr_tag>’
/usr/include/boost/function/function_template.hpp:913: error: too many initializers for ‘boost::detail::function::basic_vtable0<void>’
/usr/include/boost/function/function_template.hpp: In member function ‘bool boost::detail::function::basic_vtable0<R>::assign_to(F, boost::detail::function::function_buffer&) [with F = void (View::*)(), R = void]’:
/usr/include/boost/function/function_template.hpp:915:   instantiated from ‘void boost::function0<R>::assign_to(Functor) [with Functor = void (View::*)(), R = void]’
/usr/include/boost/function/function_template.hpp:722:   instantiated from ‘boost::function0<R>::function0(Functor, typename boost::enable_if_c<开发者_开发问答boost::type_traits::ice_not::value, int>::type) [with Functor = void (View::*)(), R = void]’
/usr/include/boost/function/function_template.hpp:1064:   instantiated from ‘boost::function<R()>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with Functor = void (View::*)(), R = void]’
boostProve_View.cpp:20:   instantiated from here
/usr/include/boost/function/function_template.hpp:492: error: no matching function for call to ‘boost::detail::function::basic_vtable0<void>::assign_to(void (View::*&)(), boost::detail::function::function_buffer&, boost::detail::function::basic_vtable0<R>::assign_to(F, boost::detail::function::function_buffer&) [with F = void (View::*)(), R = void]::tag)’

Environment: Ubuntu 10.10, g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5


9/30/11 Update) Thanks to the suggestion, I solved the issue by doing this:

crowd_->connectPostUpdate(boost::bind(&View::correctR, this));


The problem is that your slot wants a function of type void (*)(), whereas you're giving it an argument of type void (View::*)(). A member function pointer is not the same as a function pointer, unfortunately. One way you could fix this is to make correctR static, which would give it the correct signature. If that fails, you might want to investigate things such as Boost's Bind library.

See this part of the C++ FAQ Lite for more on pointers to member functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号