Hello. I have a class that holds a set of data. Each piece of data is represented by another class. I wanted to overload the += operator for the dataset class, but it appears gcc mistakes my effort as trying to use the binary + operator. Below is the related function.
Code:
CDataFile *CDataFile::operator+=(CData *wave) {
CNode *node;
node=new CNode((void *)wave);
WaveList.AddTail(node);
return this;
}
WaveList is a member object of CDataFile. Below, datafile is an instance of CDataFile and currwave one of CData. This is the statement, with which I try to add new data to the dataset:
datafile+=currwave;
However, this gives me the following error.
In function `int main(int, char**)':
error: invalid operands of types `CDataFile*' and `CData*' to binary `operator+'
error: in evaluation of `operator+=(class CDataFile*, class CData*)'
I'm a novice C++ writer, and I cannot figure out why it fails like this. It works, if I call the function as
datafile.operator+=(currwave);
and I am baffled why the actual operator overloading is causing havoc. Help!