Prepare to learn opencv, but the syntax of the first knowledge point is not understood: Typedef struct cvpoint {int X;/* x coordinate, usually based on 0 */INT y;/* Y coordinate, usually based on 0 */} cvpoint; /* Constructor */inline cvpoint (int x, int y ); Note that the cvpoint struct is C in upper case, while the cvpoint () constructor is C in lower case. If the constructor is the same, it cannot be compiled. So I searched and found out,The original struct can be used as a function parameter or as a function return value.. I used to use struct pointers all the time. I don't know what is the difference between directly using struct variables and using struct pointer variables? However, in opencv, many functions directly use struct variables. Maybe this operation is faster ??
Google has been using this for a long time and finds the answer: In this case, the function uses a copy of the struct to call the value passing belonging to the function. Operations in the function do not change the value of the original struct, but will sacrifice some speed. If you use a pointer to pass a struct variable, it is an address-based call that directly operates the struct, so the operations in the function are directly reflected on the struct. In opencv, the first is that the structure is relatively small, and the memory overhead is relatively small; the second is to avoid changing the structure itself. For more information, see. The following is an example of C/C ++. The compilation test is normal. /*************************************** * Struct variables can be directly used as function parameters, it can also be used as the return value of a function. **************************************** * // Filename: struct. C # include <stdio. h> // define a struct typedef struct point {int X; int y;} Point;
// Use a struct variable as the void display (point) {printf ("X is % d \ n", point. x); printf ("Y is % d \ n", point. y);/********* if C ++ is used, the following *************** STD :: cout <"X is" <point. x <STD: Endl; STD: cout <"Y is" <point. Y <STD: Endl; **************************************/} // Use struct variables as the return value of the function. Point setpoint (int x, int y) {point; point. x = x; point. Y = y; return point ;}
// Main function int main (INT atgc, char * argv []) {point; point = setpoint (2, 3); display (point); Return 0 ;} Running resultXIs 2y is 3 |