c++ - unresolved overloaded function type -
i'm trying write templated class holds reference object of it's template parameter type, , pointer void returning no arg member function of class. i'm getting error '<unresolved function type>' when compile.
template<class t> class memberaction { public: memberaction(void (t::*func)() , t& object); private: void (t::*m_func)(); t& m_object; }; template<class t> memberaction<t>::memberaction(void (t::*func)() , t& object) { m_func = func; m_object = object; } class file { public: file(); void telunus_open(); //memberaction<file>& getopenaction(); private: memberaction<file> m_openaction; }; file::file(): m_openaction(telunus_open,*this)//line error on { } void file::open() { // } compiling g++ 4.7.2 following error message:
stackoverloaderrorexample.cpp|31|error: no matching function call 'memberaction<file>::memberaction(<unresolved overloaded function type>, file&)'| it seems other people similar compiler error confusing pointers global functions pointers member functions, declare constructor taking pointer member function of it's template parameter, , pass member function of correct type.
so how resolve compiler error?
i believe need pass &file::telunus_open—or &file::open, whichever name you’ve called it—to member function pointer. open has function type void (file::)() whereas &file::open has type want, function pointer type void (file::*)(). beyond that, you’re going have issues m_object reference member. assignment operator try assign uninitialised reference:
template<class t> memberaction<t>::memberaction(void (t::*func)() , t& object) { m_func = func; m_object = object; } you should use constructor initializer list instead:
template<class t> memberaction<t>::memberaction(void (t::*func)() , t& object) : m_func(func), m_object(object) {}
Comments
Post a Comment