ofxCvColorImage operator += not inhereted

Hey there,
seems like a simple one. Let me know if i am missing something here:

//this compiles  
ofxCvGrayscaleImage gray1,gray2;  
gray1 += gray2;  
//this doesn't  
ofxCvColorImage color1,color2;  
color1 += color2;  

i fixed this by making the following changes, which i think is dirty and wrong but worked without much thought:

ofxCvColorImage.h >>>>>>>>>>>>>>>  
//uncomment this for += fix...   
virtual void  operator += ( ofxCvImage& mom );  //in base class  
ofxCvColorImage.c >>>>>>>>>>>>>>>  
//Added this.  
void ofxCvColorImage::operator+= ( ofxCvImage& mom ){  

the other operators are likely broken. if i am not missing something dumb, then it deserves a proper fix.


EDIT: I realized I should specify the environment:
I’m running the Xcode-FAT v0.06 on OS X 10.5.7 and Xcode version 3.1.3

Good catch.

This is definitely a bug of some sort. After doing some tests I am not sure why it is not working in the first place. The inheritance of the += operator works in all other image types. The reason why it does not inherit in ofxCvColorImage is because there are local operator += (float) functions. So for some reason there is a problem with operator overloading and inheritance. Not sure why the two operator methods are interfering even though they have different signatures. If somebody knows please let me know …

I committed your fix for +=, -+ in the color image type to the svn. Should go into the 0061 release.


hi stefan

just noticed the same some days ago with plain methods, if you inherit a method and then create an overloaded version of it in the inheriting class, the inherited one disappears. it’s the default in c++, and solved by doing:

class ofxCvColorImage: public ofxImage{  
using ofxCvImage::operator+;  

weird huh!

word, that’s the kind of fix i was looking for.

thanks for passing it along!

So there must be another piece to the puzzle

i added to ofxCvColorImage.h:

class ofxCvColorImage : public ofxCvImage {  
	using ofxCvImage::operator+=;  
	using ofxCvImage::operator-=;  

now i at this line in ofxCvImage.h:72:

	virtual void  operator += ( ofxCvImage& mom );  

I get this error:
error: ‘virtual void ofxCvImage::operator+=(ofxCvImage&)’ is inaccessible

and then,

	ofxCvColorImage color1,color2;  
	color1 += color2;  

generates compiler error:
error: within this context

must be something small, but i am definitely at the edge of my c++ inheritance wackiness knowledge.

sorry it should be:

class ofxCvColorImage: public ofxImage{
using ofxCvImage::operator+;