Why do vectors not work in ROS?
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.