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

asked 2020-09-01 21:17:14 -0500

RicoJ gravatar image

updated 2020-09-07 12:12:34 -0500

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::shared_pointer. But what about boost::shared_ptr?

edit retag flag offensive close merge delete

Comments

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

KenYN gravatar image KenYN  ( 2020-09-01 23:07:49 -0500 )edit

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();
RicoJ gravatar image RicoJ  ( 2020-09-06 10:18:44 -0500 )edit