c++ - How to initialise a matrix only when calling a function? -


i'm wondering if can this: create matrix , initialise size when calling function:

#ifndef occupancy_grid_h #define occupancy_grid_h #include <math.h>  class occupancygrid{  public:      void update_cell_value(double x, double y, double status) {         matrix[x_origin+x][y_origin+y]=status;     }      void initialize_map(){         grid_size=100;         x_origin=grid_size/2;         y_origin=grid_size/2;     }  private:     int grid_size;     int x_origin;     int y_origin;     int const map[grid_size][grid_size] = {-1}; };  #endif 

is there better way this?

thank you

use std::vector<std::vector<t>>. ideally initialise in constructor if must initialize later in loop. example:

class occupancygrid { public:         void initialize_matrix(unsigned size){         matrix.resize(size);         for(auto& v : matrix)             v.resize(size);     }  private:     std::vector<std::vector<double>> matrix; }; 

or boost.multiarray.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -