Ask Your Question
0

How to use C++ linked list in Ros node??

asked 2016-04-17 07:42:05 -0500

Moon gravatar image

updated 2016-04-18 14:03:55 -0500

gvdhoorn gravatar image

to use the linked list in a Cpp code we use include<list> .. but it doesn't work for a ROS node,SO how can I use it in a ROS node??!!

I assume that the problem that cmakelists should has something to declare the C++ standard libraries my catkin_make output:

/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp: In constructor ‘Graph::Graph(int)’:
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:25:12: error: expected type-specifier before ‘list’
  adj = new list<int>[V];
            ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:25:12: error: expected ‘;’ before ‘list’
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:26:9: error: expected primary-expression before ‘int’
  tree = int[V][V];
         ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:26:9: error: expected ‘;’ before ‘int’
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp: In member function ‘void Graph::GridToGraph(int, int)’:
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:54:6: error: ‘g’ was not declared in this scope
      g.addEdge(grid[k][j], grid[k + 1][j]);
      ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:61:5: error: ‘g’ was not declared in this scope
     g.addEdge(grid[k][j], grid[k][j + 1]);
     ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:66:5: error: ‘g’ was not declared in this scope
     g.addEdge(grid[k][j], grid[k][j + 1]);
     ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp: In member function ‘void Graph::prim_st()’:
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:95:5: error: ‘list’ was not declared in this scope
     list<int>::iterator i;
     ^
/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:95:5: note: suggested alternatives:
In file included from /usr/include/c++/4.8/list:63:0,
                 from /opt/ros/indigo/include/ros/forwards.h:35,
                 from /opt/ros/indigo/include/ros/common.h:37,
                 from /opt/ros/indigo/include/ros/ros.h:43,
                 from /home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:4:
/usr/include/c++/4.8/bits/stl_list.h:438:11: note:   ‘std::list’
     class list : protected _List_base<_Tp, _Alloc>
           ^
In file included from /usr/include/boost/mpl/aux_/include_preprocessed.hpp:37:0,
                 from /usr/include/boost/mpl/list.hpp:46,
                 from /usr/include/boost/math/policies/policy.hpp:9,
                 from /usr/include/boost/math/policies/error_handling.hpp:19,
                 from /usr/include/boost/math/special_functions/round.hpp:14,
                 from /opt/ros/indigo/include/ros/time.h:58,
                 from /opt/ros/indigo/include/ros/ros.h:38,
                 from /home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:4:
/usr/include/boost/mpl/aux_/preprocessed/gcc/list.hpp:22:8: note:   ‘boost::mpl::list’
 struct list;
        ^
In file included from /usr/include/boost/lexical_cast.hpp:170:0,
                 from /opt/ros/indigo/include/ros/transport_hints.h:34,
                 from /opt/ros/indigo/include/ros/subscribe_options.h:33,
                 from /opt/ros/indigo/include/ros/node_handle.h:41,
                 from /opt/ros/indigo/include/ros/ros.h:45,
                 from /home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:4:
/usr/include/boost/container/container_fwd ...
(more)
edit retag flag offensive close merge delete

Comments

1

There is nothing special about ROS, and #include <list> should just work. Please include whatever error messages or output you see when trying to do that, and please include how you are setting things up and then building your nodes.

gvdhoorn gravatar image gvdhoorn  ( 2016-04-17 08:00:06 -0500 )edit

I edit my question adding the errors :)

Moon gravatar image Moon  ( 2016-04-18 13:18:23 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2016-04-18 13:34:30 -0500

ahendrix gravatar image

Your error is:

/home/ubuntu/catkin_ws/src/moon/src/SpanningTree.cpp:25:12: error: expected type-specifier before ‘list’ adj = new list<int>[V];

The types in the C++ standard library are provided in the std namespace.

It looks like either you forgot to prefix your use of list with the std:: namespace, or you forgot to add using namespace std; to the top of your cpp file.

I _strongly_ prefer and recommend using the std:: prefix. The using namespace ...; clause can cause name collisions and other surprises. (most C++ books have an opinion on this, too).

edit flag offensive delete link more

Comments

thanks that work ;)

Moon gravatar image Moon  ( 2016-04-18 14:29:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-17 07:42:05 -0500

Seen: 593 times

Last updated: Apr 18 '16