I have a simple class representing a triangle, which contains three arrays.
class Triangle
{
public:
double X[3];
double Y[3];
unsigned char color[3];
};
I want to create objects of this class on the heap, then pass them to a function that will use values from the arrays. Since I am passing in these objects, I need a copy constructor to make a deep copy. The problem arises when allocating the new arrays in the copy constructor.
This is what I have thus far:
Triangle (const Triangle &obj)
{
X = new double[3];
Y = new double[3];
color = new unsigned char[3];
for (int i=0; i<3; ++i)
{
X[i] = obj.X[i];
Y[i] = obj.Y[i];
color[i] = obj.color[i];
}
}
I keep getting the following error: " error: array type 'double [3]' is not assignable" for each of the three arrays.
I am taking the same approach as discussed in this video, and I cannot figure out why I am unable to make a new array. The answer to this question also has the same approach.
Does anyone have any insights? I feel like I am just missing something really silly.