Robotics StackExchange | Archived questions

Why does the keyword auto not work for boost::shared pointer?

Hi,

I am running into a situation where boost::shared_ptr<costmap_2d::InflationLayer> inflation_layer_ptr = some_func(); works, but auto inflation_layer_ptr = some_func() does not. some_func() is a function that returns a boost::shared_ptr<costmap_2d::InflationLayer> object.

I am using C++11 and ROS Kinetic. My understanding is in C++11, the keyword auto should work with std::sharedpointer. But what about boost::sharedptr?

Asked by RicoJ on 2020-09-01 21:17:14 UTC

Comments

Please add what error you are seeing and the signature of some_func() at least; it should work.

Asked by KenYN on 2020-09-01 23:07:49 UTC

The error I see is error: ‘inflation_layer’ does not name a type. A minimal example is

boost::shared_ptr<costmap_2d::InflationLayer> some_func() {
            return boost::shared_ptr<costmap_2d::InflationLayer>();}
auto inflation_layer_ptr = some_func();

Asked by RicoJ on 2020-09-06 10:18:44 UTC

Answers