0

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!

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by pilotkid424
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.