c++ - Creating Array of Classes -


i got class such as:

class me362 { public:     void geometry(long double xlength);     void mesh(int xnode);     void properties(long double h, long double d, long double k,long double q, long double dt,long double pho,long double cp, long double tinf);     void drichlet(long double tleft,long double tright);     void neumann(bool tlinks, bool trechts);     void updatediscretization(long double**** a,long double* b, long double* tp);     void printvectortofile(long double *x); private:     int xdim;     long double xlength;     long double tleft;     long double tright;     long double h;     long double d;     long double k;     long double q;     long double dt;     long double cp;     long double rho;     long double tinf;     bool tlinks;     bool trechts; }; 

and initialize using

me362 domain1; me362 domain2; me362 domain3; 

but want determine number of domains want initialize. need dynamic array of me362 structures. how can that? can done?

thank all,

emre.

use std::vector, handles dynamic memory you:

#include <vector>  // ...  std::vector<me362> domains; 

std::vector has lot of nice features , guarantees, being layout-compatible c, having locality of reference, 0 overhead per element, , on.

also note std::vector has constructor takes integral argument, , creates many elements:

// create vector 42 default-constructed me362 elements in std::vector<me362> domains(42); 

see standard library reference (like cppreference.com or cplusplus.com) details using std::vector.)


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -