【发布时间】:2016-11-28 12:35:41
【问题描述】:
我对 C++ 还很陌生,所以这个问题听起来可能很愚蠢,但即使我在谷歌上搜索了一段时间,我也找不到答案。我用的是ROS环境,不过我的问题应该是一般的C++问题,所以决定贴在这里。
我有两个代码
1)
ros::Duration max_storage_time = ros::Duration().fromNSec(1ULL * 1000000000LL);
tf::TimeCache odometryCache(max_storage_time);
2)
tf::TimeCache odometryCache(ros::Duration max_storage_time = ros::Duration().fromNSec(1ULL * 1000000000LL));
第二个编译,而第一个不编译。对我来说,似乎完全一样。第一个代码的错误是:
对tf::TimeCache::TimeCache(ros::Duration)的未定义引用
tf::TimeCache 的文档可以在http://docs.ros.org/jade/api/tf/html/c++/classtf_1_1TimeCache.html#acca87a70aeb9c3573cdbfec26f6bfe23找到
有人可以告诉我我缺少什么吗?代码片段的区别在哪里,为什么第一个不能编译?
提前致谢!
【问题讨论】:
-
当您执行
ros::Duration max_storage_time = ros::Duration().fromNSec(1ULL * 1000000000LL)时,您想在构造函数调用中做什么?你复制了ros::Duration max_storage_time =部分吗? -
是的,我确定,第二个(仅使用一行)有效。
标签: c++ variables constructor ros