c++ - Get arrays from other classes -


i working on ludum dare project , can't figure out how use array in class using tilesheet. best way store array in class , use in main.cpp file?

one way use stl vector class array. in below sample, nnumbers vector of type int , copy made through public accessor method classb uses.

// classa.h #include <vector>  class classa { public:     classa();      std::vector<int> getnumbers();  private:     std::vector<int> mnumbers; };   // classa.cpp #include "stdafx.h" #include "classa.h"  classa::classa() {     for(int = 0; < 5; i++)     {         mnumbers.push_back(i);     } }  std::vector<int> classa::getnumbers() {     return mnumbers; }   // classb.cpp #include "stdafx.h" #include "classb.h" #include "classa.h"  #include <vector> #include <iostream>  void classb::runoutput() {     classa a;     std::vector<int> somenumbers = a.getnumbers();     for(unsigned int = 0; < somenumbers.size(); i++)     {         std::cout << "i = " << << std::endl;     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -