Error: function returning a function

Despite the fact that there is at least one similar question , I still ask me because it has not been resolved and seems more complicated. I am trying to simplify my work.

I have a .cpp file that uses .h, as shown below, and compiles the sheds error as follows. Any idea is appreciated. Please note that codes are simplified to minimize the display of only the problematic parts.

FC_boost_prove.h:

#ifndef FC_H #define FC_H #include <vector> #include "iostream" #include "boost/signal.hpp" #include "boost/bind.hpp" #include <boost/random.hpp> typedef boost::signal0<void()> PreUpdateSignal; typedef PreUpdateSignal::slot_function_type PreUpdateSlot; typedef boost::signal0<void()> PostUpdateSignal; typedef PostUpdateSignal::slot_function_type PostUpdateSlot; class FC { public: FC(uint width, uint height) { std::cout << "In constructor." << std::endl; } ~FC() { //Do ... } void connectPreUpdate(PreUpdateSlot s) { preUpdateSignal_.connect(s); } void connectPostUpdate(PostUpdateSlot s) { postUpdateSignal_.connect(s); } protected: PreUpdateSignal preUpdateSignal_; PostUpdateSignal postUpdateSignal_; }; #endif 

FC_boost_prove.cpp:

 #include <iostream> #include <string> #include "FC_boost_prove.h" int main() { std::cout << "test." << std::endl; } 

Compilation Error:

 $ g++ FC_boost_prove.cpp In file included from /usr/include/boost/signals/signal_template.hpp:22, from /usr/include/boost/signals/signal0.hpp:24, from /usr/include/boost/signal.hpp:19, from FC_boost_prove.h:7, from FC_boost_prove.cpp:3: /usr/include/boost/last_value.hpp: In instantiation of 'boost::last_value<void()>': /usr/include/boost/signals/signal_template.hpp:178: instantiated from 'boost::signal0<void(), boost::last_value<void()>, int, std::less<int>, boost::function0<void()> >' FC_boost_prove.h:12: instantiated from here /usr/include/boost/last_value.hpp:22: error: function returning a function In file included from /usr/include/boost/signals/signal0.hpp:24, from /usr/include/boost/signal.hpp:19, from FC_boost_prove.h:7, from FC_boost_prove.cpp:3: /usr/include/boost/signals/signal_template.hpp: In instantiation of 'boost::signal0<void(), boost::last_value<void()>, int, std::less<int>, boost::function0<void()> >': FC_boost_prove.h:12: instantiated from here /usr/include/boost/signals/signal_template.hpp:330: error: function returning a function /usr/include/boost/signals/signal_template.hpp:370: error: function returning a function In file included from /usr/include/boost/function/detail/maybe_include.hpp:13, from /usr/include/boost/function/function0.hpp:11, from /usr/include/boost/signals/signal_template.hpp:38, from /usr/include/boost/signals/signal0.hpp:24, from /usr/include/boost/signal.hpp:19, from FC_boost_prove.h:7, from FC_boost_prove.cpp:3: /usr/include/boost/function/function_template.hpp: In instantiation of 'boost::function0<void()>': FC_boost_prove.h:24: instantiated from here /usr/include/boost/function/function_template.hpp:1006: error: function returning a function /usr/include/boost/function/function_template.hpp: In instantiation of 'boost::detail::function::basic_vtable0<void()>': /usr/include/boost/function/function_template.hpp:856: instantiated from 'void boost::function0<R>::clear() [with R = void()]' /usr/include/boost/function/function_template.hpp:752: instantiated from 'boost::function0<R>::~function0() [with R = void()]' /usr/include/boost/signals/slot.hpp:105: instantiated from here /usr/include/boost/function/function_template.hpp:486: error: function returning a function /usr/include/boost/function/function_template.hpp:643: error: function returning a function 

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

+4
source share
1 answer

Why are you specifying boost::signal0<> ? The signalN patterns are for missing compilers that cannot properly parse function signatures.

Use a signal and indicate the signature of the function, as recommended for modern compilers:

 typedef boost::signal<void()> PreUpdateSignal; typedef boost::signal<void()> PostUpdateSignal; 

or use signalN and specify the return type (and each type of argument) explicitly, if necessary for missing compilers:

 typedef boost::signal0<void> PreUpdateSignal; typedef boost::signal0<void> PostUpdateSignal; 
+4
source

All Articles