Hi all, I'm having a similar problem with a code of mine. <<note: split from here>>
In my code I have a class in which I am trying to implement a dynamic array of structs. My compiler does not seem to like my deconstructor, and complains that my dynamic array was not declared in that scope. The code is pretty sparse as I'm just trying to ensure I understand proper declarations.
I've tried writing the same code with dynamic array of ints instead (for practice), and it compiled without complaint.
Any insight you all can offer would be greatly appreciated, as I'm fairly new to OO.
#include<iostream>
using namespace std;
struct COORD_STRUCT // Structure to hold X,Y, and Z coordinates for spheres
{
double X;
double Y;
double Z;
};
class HARD_SPHERE_COORDS // Class to contain all system's spheres and operate on them
{
int N; // System size
COORD_STRUCT *COORDINDATES; // Pointer to array to hold system's coordinates
public:
HARD_SPHERE_COORDS(); // Constructor
~HARD_SPHERE_COORDS(); // Deconstructor
};
int main()
{
// empty for now
return 0;
}
HARD_SPHERE_COORDS::HARD_SPHERE_COORDS() // Set array to hold N spheres
{
int N;
COORD_STRUCT * COORDINATES;
COORDINATES = new COORD_STRUCT[N];
}
HARD_SPHERE_COORDS::~HARD_SPHERE_COORDS() // Cleanup memory
delete [] COORDINATES;
}