![]() |
| | #1 |
| Registered User Join Date: Aug 2006
Posts: 61
| allocatable arrays in CLASSes and STRUCTS I am using a struct and a Class whose elements may be arrays. I would like though, for these arrays to be dynamically allocatable when I declare them in the Class and main code; how is it supposed to be done in C++? I was firstly trying to do it in C, but I prefer to try in C++ because I have files to read and find it easier for them to be read in C++. I wrap my code here; it's very simple, however, please let me know if there are more information that you need Thank you in advance, Best S.M Code:
typedef struct VertexTag{
float x; //x-coord of Vertex
float y; //y-coord of Vertex
float z; //z-coord of Vertex
} typeVertex;
//*******************************************************************//
// Domain class:
//*******************************************************************//
class Mesh{
public:
typeVertex coords[ SIZE_TO_BE_ALLOCATED_DYNAMICALLY ];
Mesh(void); // constructor
};
|
| simone.marras is offline | |
| | #2 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,366
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #3 |
| Registered User Join Date: Aug 2006
Posts: 61
| |
| simone.marras is offline | |
| | #4 | |
| The larch Join Date: May 2006
Posts: 3,082
| Just as you'd do it with an array.
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #5 |
| Registered User Join Date: Aug 2006
Posts: 61
| Thank you a lot, I will try it sometime soon. All the best |
| simone.marras is offline | |
![]() |
| Tags |
| allocation, class, dynamic, structs |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Structs or classes? | legit | C++ Programming | 4 | 06-28-2009 10:16 AM |
| classes, structs and unions | Luciferek | C++ Programming | 24 | 08-09-2008 10:26 AM |
| Why use Classes instead of Structs? | yaya | C++ Programming | 12 | 03-16-2008 12:39 AM |
| Are structs and classes the same thing? | dwks | C++ Programming | 6 | 11-25-2005 03:21 PM |
| Classes or Structs faster for Lists | White Rider | C++ Programming | 24 | 04-05-2002 03:57 PM |