Function passed by pointers or reference

Hi again,

I learned basic about C and C++ but my programming skills are bad. I am going to read some codes about image processing and I need to understand functions like this one below?

 
BOOL Trans_Geo_Affine(CImage *pImgSrc, CImage *pImgDst, BOOL bMatrix, BOOL bHvInversed, double fScale_xx, double fFlex_xy, double fSkew_yx, double fRotate_yy, double fTx, double fTy, int nInterpolation, BOOL bResize, BYTE cFill) 

http://read.pudn.com/downloads6/sourcecode/multimedia/21391/MotionStabilization/ImageProcess.cpp__.htm
I am confused about two parameters, CImage *pImgSrc and CImage *pImgDst.
I think they are class pointers and the function is passed by reference.
Could you suggest what should I learn to understand this function and its parameters?
How should I use this function? If possible please tell me how to use the function with two parameters CImage *pImgSrc and CImage *pImgDst. Thank you.

Last edited on
Yes, they are class pointers, but what do you mean by "the function is passed by reference"? The function isn't being passed anywhere in the prototype.

If you read the comment above the function, there is some documentation about what it does (assuming you understand the purpose of the library, as I have no idea what an affine transform is) as well as descriptions of what most of the parameters are for.
Thanks. I am confused by function using class pointers as parameters and function which parameters are passed by reference.
For example, if I declare two variables as follows, which one is correct to use that function?
1
2
3
CImage a, b;
Trans_Geo_Affine(a, b,...)
Trans_Geo_Affine(&a, &b,...)
Remember that the & operator here is taking the address of the object it is applied to. Therefore:
In line 2, you are passing two CImage objects.
In line 3, you are passing two addresses of CImage objects.

Look again at the prototype for the function and you should be able to determine which the function is looking for. Does it want actual objects or addresses?
Actually, I am not sure.

CImage *pImgSrc is a pointer, so I think we need a pointer here.
And therefore, #3 is right here. Am I correct?

Another example, if I declare two pointers as follows, are they used correctly in the function?

1
2
CImage *a, *b;
Trans_Geo_Affine(a, b,...)
are they used correctly in the function?
Unlikely. The pointers do not refer to a valid object
Sorry, I don't understand that. Could you explain more?
@ OP: Pointers have to point to something. For them to point to a valid object they would need to have been initialized like this for example:
 
CImage* a = new CImage, * b = new CImage;

Otherwise they hold whatever information is representative of the residual charge left over in that area of the RAM module from the last time it was used.

Now there are times when the documentation for some (likely) C based API tells you to pass a pointer into a function and that this pointer will receive the address of whatever variable and so you don't actually have to allocate the memory your self. If that is the case then you should still initialize them, but instead of a dynamic object you would point them to NULL:
 
CImage* a = NULL, * b = NULL;
You need to go through the basics
Thanks!
If I initialize these pointers as bellow, are they used correctly in the function?

 
CImage* a = new CImage, * b = new CImage;


I am wondering which one is correct.
Case 1:

 
Trans_Geo_Affine(a, b,...)


Case 2:

 
Trans_Geo_Affine(&a, &b,...)

You can determine this yourself by looking at the function prototype. Note that a and b are both of type CImage*, so do you want to pass a and b or &a and &b?
According to the function prototype, I think it should be passed a and b.
Please confirm.
Topic archived. No new replies allowed.