Overloaded parenthesis operator
I'm using the EasyBMP library. I have a function that returns a BMP*
object. BMP objects have the parenthesis overloaded, where I can do:
BMP image;
*image(x,y)->Red=0;
But now that I'm trying to return a pointer, I want to do:
BMP *image;
*image(x,y)->Red=0;
but I get an error saying that image cannot be used as a function. How do I fix this?
BMP* image = getimageptr();
*(*image)(x,y)->Red=0;
Or, perhaps better:
BMP* image_ptr = getimageptr();
BMP& image = *image_ptr;
*image(x,y)->Red=0;
(BTW, do you really dereference that object returned by op()
before dereferencing it again to access Red
? Seems odd!)
The problem is that in the second example, image
is of type BMP*
, not BMP
; since operator()
is overloaded on BMP
, you need to dereference the pointer before you use the call operator.
Hence, I think you will need to use:
*(*image)(x,y)->Red = 0;
I'm away from a compiler right now, so you'll have to forgive me if I messed up.
Please read through the C++ FAQ #13.10. This FAQ item discusses overloading operator()
for use with matrices. I believe this is what you want to do.
The FAQ also shows how to use the operator as well.
精彩评论