I’m using a CvPoint structure in OpenCV and I need to assign a value to x and y fields of the structure.
Here is my code:
CvPoint* P1;
P2[0].x=32;
But the programs always block while trying to set the value.
Any idea about how to set these values?
Well first of all P1 is a pointer to an object of type P1. In order to assign something to an object’s member via its pointer you need to use the -> operator. If this pointer points to the beginning of an array you use the operator[] to access individual elements. This operator returns a reference for the given index, in this case CvPoint& .
1. dynamic allocation of a single object
2. dynamic allocation or an array
Since in both examples the new operator has been used, it is mandatory to pair them with a matching call to delete or delete[] in case of an array.