虽然至少有one similar question,但我仍然问我的,因为那个没有解决,看起来更复杂。我正在努力简化我的。
我有一个.cpp文件,使用如下的.h,并按如下方式编译这些棚子错误。任何想法都表示赞赏。请注意,代码已经过简化,以便最低限度地显示有问题的部分。
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;
}
编译错误:
$ 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
环境:Ubuntu 10.10,g ++(Ubuntu / Linaro 4.4.4-14ubuntu5)4.4.5
答案 0 :(得分:4)
为什么要指定boost::signal0<>
?信号 N 模板用于无法正确解析函数签名的缺陷编译器。
使用信号并指定函数签名,如现代编译器所推荐的那样:
typedef boost::signal<void()> PreUpdateSignal;
typedef boost::signal<void()> PostUpdateSignal;
或使用signal N 并根据缺陷编译器的需要明确指定返回类型(和每个参数类型):
typedef boost::signal0<void> PreUpdateSignal;
typedef boost::signal0<void> PostUpdateSignal;