C++ Array Type Not Assignable in Copy Constructor -
I have a simple class that represents the triangle, which consists of three arrays
< Code> square triangle {public: double x [3]; Double y [3]; Unsigned four colors [3]; };I want to create objects in this square on the heap, then pass on those functions which will use the value from the array. Since I am in these items, I need to make a deep copy to make a copy.
Triangle (const triangle and obj) {X = new double [3]; Y = new double [3]; Color = new unsigned char [3]; For (int i = 0; i
I keep the following error: "Error: array type 'double [3]' is not assignable for each of the three arrays.
I am taking the same view as discussion, and I do not know why I am unable to create a new array. The answer is also the same approach.
Does anyone have any insights? Looks like I'm really stupid.
I'm taking the same approach as discussed in this video.
In the video, you can see that he started the array Read on the member-preliminary list and how it is different from specifying the data members inside the controller body.
You can also see that they used an indicator and the dynamic form Allowed by
new . It is necessary (S IC) If the shape of the array is not known in time compilation, in your case it is known as
3 , hence there is no need for
new .
Once you have announced the array, you have an array there is no need to allocate new memory and make copies of things because space is already allocated to the array. @WOWOKraig said that you do not even need a per-constructor because nobody generates them which is what you need.
The answer to this question is also the same approach. / P>
Simple, C ++ is not Java.
Comments
Post a Comment