ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why do vectors not work in ROS?

asked 2013-10-27 03:57:48 -0600

JP gravatar image

updated 2013-11-18 07:28:10 -0600

tfoote gravatar image

H everyone, I can compile the following code in Xcode but I cannot do the same when using rosmake. Here is my .h file:

#ifndef __AStartAlgorithm__AStarAlgorithm__
#define __AStartAlgorithm__AStarAlgorithm__

#include <iostream>
#include <vector>

class AStarAlgorithm{

public:

AStarAlgorithm();
void astar();

 void printmap(std::vector < std::vector<int> >map);

 private:

 };
#endif /* defined(__AStartAlgorithm__AStarAlgorithm__) */

Here is my .cpp:

#include "../header/AStarAlgorithm.h"
#include <iostream>
#include <vector>
AStarAlgorithm::AStarAlgorithm(){


}



void AStarAlgorithm::astar(){

   std::vector<std::vector<int> > map  = {{8,8,8,8,8,8,8},{8,0,0,0,0,0,8},{8,0,0,0,0,0,8},{8,0,1,0,0,2,8},{8,0,0,0,0,0,8},{8,0,0,0,0,0,8},{8,8,8,8,8,8,8}};

   // printmap(map);  
}

/*
void AStarAlgorithm::printmap(std::vector < std::vector<int> >map){

    for(int i = 0; i < map.size(); i++){
        for(int j = 0; j < map[i].size(); j++){
            if(map[i][j] <10){
                std::cout << "|"<<map[i][j] << " |";
            }else{
                std::cout << "|"<<map[i][j] << "|";
            }

        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}
*/

I want to print out the vector with the commented out code but the problem at the moment is just initialising the vector. Here is my error in ROS:

/home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp: In member function ‘void AStarAlgorithm::astar()’:
/home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp:17:154: error: in C++98 ‘map’ must be initialised by constructor, not by ‘{...}’
/home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp:17:154: error: deducing from brace-enclosed initialiser, list requires #include <initializer_list>
/home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp:17:154: error: deducing from brace-enclosed initialiser, list requires #include <initializer_list>
/home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp:17:154: warning: extended initialiser lists only available with -std=c++0x or -std=gnu++0x [enabled by default] /home/jay/fuerte/sandbox/ucl_drone/src/trajectory/AStarAlgorithm.cpp:17:154: error: could not convert ‘{{8, 8, 8, 8, 8, 8, 8}, {8, 0, 0, 0, 0, 0, 8}, {8, 0, 0, 0, 0, 0, 8}, {8, 0, 1, 0, 0, 2, 8}, {8, 0, 0, 0, 0, 0, 8}, {8, 0, 0, 0, 0, 0, 8}, {8, 8, 8, 8, 8, 8, 8}}’ from ‘<brace-enclosed initializer="" list="">’ to ‘std::vector<std::vector<int> >’

Any help will be much appreciated! Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2013-10-27 04:17:12 -0600

Take a look here: http://stackoverflow.com/questions/2172053/c-can-i-statically-initialize-a-stdmap-at-compile-time

I'm guessing this is happening because Xcode uses LLVM/Clang and rosmake uses gcc.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-10-27 03:57:48 -0600

Seen: 795 times

Last updated: Oct 27 '13