开发者

error: function returning a function

Although there is at least one similar question, I still ask mine since that one hasn't got solved and seems more complicated. I'm trying to simplify mine.

I have a .cpp file that uses .h as below, and compiling these sheds error as follows. Any idea is appreciated. Note that codes are simplified in order to minimally show the problematic parts only.

FC_boost_prove.h:

#ifndef FC_H
#define FC_H

#include <vector>
#include "iostream"

#include "boost/signal.hpp"
#include "boost/bind.hpp"
#inc开发者_Go百科lude <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;
}

Compile 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


Why are you specifying boost::signal0<>? The signalN templates are for deficient compilers that can't properly parse function signatures.

Either use signal and specify the function signature, as recommended for modern compilers:

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

or use signalN and specify the return type (and every argument type) explicitly, as needed for deficient compilers:

typedef boost::signal0<void> PreUpdateSignal;
typedef boost::signal0<void> PostUpdateSignal;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜