SFINAE 模板错误
SFINAE Template Error
我正在使用SFINEA订阅ROS中的通用主题,它侦听每个主题,并使用SFINEA返回header.stamp
时间(如果存在(。这在反序列化中工作得更快。唯一的问题是我在设置订阅者时遇到问题。我不断收到以下编译错误:
CMakeFiles/performance_tracker.dir/src/performance_tracker.cpp.o:
In function PerformanceTracker::topicCallback(boost::shared_ptr<topic_tools::ShapeShifter>)
ros/src/performance_tracker/src/performance_tracker.cpp:32:
undefined reference to boost::disable_if<timewarp::has_header<boost::shared_ptr<topic_tools::ShapeShifter> >, ros::Time>::type
timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter> >(boost::shared_ptr<topic_tools::ShapeShifter>)
主要
// Subscribe To Generic Message
_sub = _nh.subscribe( _topicName, 1, &PerformanceTracker::topicCallback, this);
void PerformanceTracker::topicCallback(const boost::shared_ptr<topic_tools::ShapeShifter> data){
//Current Time
ros::Time begin = ros::Time::now();
ros::Time timePublished = timewarp::extractTime<boost::shared_ptr<topic_tools::ShapeShifter>>(data);
}
命名空间类
namespace timewarp
{
template <typename T>
struct has_header {
typedef char yes[1];
typedef char no[2];
template <typename C>
static yes& test(typename C::_header_type*);
template <typename>
static no& test(...);
// If the "sizeof" the result of calling test<T>(0) would be equal to the sizeof(yes),
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter> data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<topic_tools::ShapeShifter>);
}
您正在将boost::shared_ptr<topic_tools::ShapeShifter>
类型作为MsgType传递给has_header<T>
而不是topic_tools::ShapeShifter
。
我相信你想做:
ros::Time timePublished = timewarp::extractTime<topic_tools::ShapeShifter>(data);
并在您使用时使用 const refs 参数:)
template<class MsgType>
typename boost::enable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>& data)
{
boost::shared_ptr<MsgType> ptr = data->instantiate<MsgType>();
assert(ptr);
return ptr->header.stamp;
}
template<class MsgType>
typename boost::disable_if<has_header<MsgType>, ros::Time>::type extractTime(const boost::shared_ptr<MsgType>&)
{
return ros::Time::now();
// or whatever ros time you need to return for types without headers
}
}
相关文章:
- VS2017 上 SFINAE 的编译错误
- 进行 SFINAE 练习时编译错误
- 尝试编译SFINAE检查中使用的方法体时发生编译错误
- C++ 带有 decltype 的 SFINAE:替换失败成为错误?
- 使用模板时可能是编译器中的 SFINAE 错误?
- 尝试使用具有尾随返回类型的 lambda 进行 SFINAE 时出现硬错误
- 如何对 SFINAE 进行"deep",即当替换导致代码中进一步出现一些编译错误时?
- 尾随返回类型中带有 SFINAE 的 GCC 错误
- 防止编码器错误 - 忘记在"std::enable_if<>::type"中添加"::type" (SFINAE)
- 为什么这个 SFINAE 在 gcc 中给出错误
- 在模板 SFINAE 约束中使用间接寻址级别会导致硬错误
- 使用C ,使用SFINAE测试静态成员的存在,返回错误的值
- 将 SFINAE 上下文中不正确的模板实例化的硬错误转变为软错误
- 在VS2015编译中键入Sfinae,但会产生错误
- VC++ SFINAE 给出错误 C2070:"重载函数":操作数大小非法
- 从MSVC2015更新2移植到GCC 5.3-SFINAE错误
- C++模板sfinae错误
- 模板实例化上的SFINAE错误
- 使用 SFINAE 但不创建编译错误
- 替换失败不是static_cast的错误(SFINAE)问题