使用Metrowerks编译器解决boost.thread编译错误
我正在尝试将 boost.thread 与 Metrowerks Codewarrior 5.5.3 一起使用; 在 header thread.hpp 中,我收到错误,他正在重新定义 thread::thread_data:
class BOOST_THREAD_DECL thread
{
private:
...
template<typename F>
struct thread_data:
detail::thread_data_base
{
F f;
thread_data(F f_):
f(f_)
{}
thread_data(detail::thread_move_t<F> f_):
f(f_)
{}
void run()
{
f();
}
};
...
};
template<typename F>
struct thread::thread_data<boost::reference_wrapper<F> >:
detail::thread_data_base
{
F& f;
thread_data(boost::reference_wrapper<F> f_):
f(f_)
{}
void run()
{
f();
}
};
我看到,实际上,thread::thread_data 似乎被声明了两次。 那里使用了什么 C++ 功能? 我怎样才能克服编译器的缺陷?
I'm trying to use boost.thread with metrowerks codewarrior 5.5.3; in the header thread.hpp, I get the error that he's redefining thread::thread_data:
class BOOST_THREAD_DECL thread
{
private:
...
template<typename F>
struct thread_data:
detail::thread_data_base
{
F f;
thread_data(F f_):
f(f_)
{}
thread_data(detail::thread_move_t<F> f_):
f(f_)
{}
void run()
{
f();
}
};
...
};
template<typename F>
struct thread::thread_data<boost::reference_wrapper<F> >:
detail::thread_data_base
{
F& f;
thread_data(boost::reference_wrapper<F> f_):
f(f_)
{}
void run()
{
f();
}
};
I see that, in effect, thread::thread_data seems to be declared twice.
What C++ feature is used there? How can I overcome that compiler deficiency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二个实例是模板类的部分特化,这是有效的 C++,不应导致重新定义错误。
过去,我在 Metrowerks 编译器中也遇到过此类功能的问题,更具体地说,当使用具有默认值的模板模板参数时,编译器永远不会编译它。 我的解决方法相当简单,不提供默认值...(1)
如果我是你,我会尝试为你的特定类型添加完整的专业化,并希望编译器为这些使用一些不同的编译路径并让你过去这个....
(这只是一个疯狂的猜测,我现在没有/使用 Metrowerks 编译器)
(1)说实话,这是很多年前的事了,我认为当时没有任何编译器完全编译模板。
The second instance is a partial specialization of the template class, this is valid C++ and should not result in a redefinition error.
I've had problems with such features in a metrowerks compilers in the past too though, more specifically, when using template template parameters with default values, the compiler would never compile it. My workaround was rather easy, don't provide a default value... (1)
If I were you I'd try adding a full specialization for your specific type, and hope the compiler uses some different compile path for those and gets you past this....
(this is just a wild guess, I don't have/use a metrowerks compiler these days)
(1) To be honest, this was many years ago, I don't think any compiler compiled templates fully back then.