By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

array of class

P: 2
Hi every body . I am using gcc3.4.6 on RH EL4. I am making a mistake and do not know what it is. I have two classes Face an Cell. The Cell class have four or more Face classes. I would like to put the classes in an array. This is what I did and get a compile error: no match for call to `(Face) (int, int, int[4])'

I instantiate cell_face[] like this
int fv[4];
cell_face[0](4, 0, fv);

The classes
Expand|Select|Wrap|Line Numbers
  1. class Face {
  2. public:
  3.    Face();
  4.    Face(int v, int fn, int* fv);
  5.    ~Face();
  6.  
  7.   int get_face_number ( );
  8.   int* get_face_verts ( );
  9.  
  10. private:
  11.    int face_number;
  12.    int face_verts[];
  13.  
  14.   void set_face_number ( int value );
  15.   void set_face_verts ( int value );
  16. };
  17.  
  18. class Cell {
  19.  
  20. public:
  21.    Cell() ;
  22.    Cell(int n, int v, int* cv);
  23.    ~Cell();
  24.  
  25.   int get_cell_number ( );
  26.   int*  get_cell_verts ( );
  27. private:
  28.    int cell_number;
  29.    int cel_verts[];
  30.    Face cell_face[];
  31.  
  32.   void set_cell_number (int value );
  33.   void  set_cell_verts (int value);
  34. };
  35.  
Nov 16 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
You can define members as

int cel_verts[];
Face cell_face[];

you have to give a size for the arrays e.g.

int cel_verts[10];
Face cell_face[10];

If you do not know the size till runtime then either use a template class or dynamically allocate the memory.

Expand|Select|Wrap|Line Numbers
  1.  
  2. template <int SIZE>
  3. class cell {
  4.  
  5.  
  6.  
  7.    int cel_verts[SIZE];
  8.    Face cell_face[SIZE];
  9.  
  10. }
  11.  
  12. or
  13.  
  14. class cell {
  15.  
  16.  
  17.  
  18.    int *cel_verts;     // use new to allocate data for these once size is known.
  19.    Face *cell_face;
  20.  
  21. }
  22.  
  23.  
Nov 16 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.