I am trying to create a function which adds an array to another array and replaces the data in the 1st array with the new data. For example, A=A+B. However, when I write my code as below, I get the error C2676:binary '[' : 'const Matrix' does not define this operator or a conversion to a type acceptable to the predefined operator.

void Matrix::add(const Matrix&m){
    for(int i=0; i<9; i++){
        data[i]=data[i]+m[i];
    }
}

Thanks in advanced for the help!

Most likely what you wanted was this:

data[i] = data[i] + m.data[i];

Since the error suggests you don't overload the subscript operator to get the contents of data, you need to touch m's copy of data directly.

Thanks, that fixed it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.