Operator Overloading Syntax Problem

Just need someone to point me in the right direction with my syntax in C++. I have a Matrix class with these declarations:

1
2
3
4
5
6
  private:
	//private member variables
  public:
	//public functions
	Matrix operator+(); //overloading operator to add two matrices
	Matrix operator-(); //overloading operator to subtract two matrices 



I'm getting a syntax problem with the overloading operator that says:

"Error 3 error C2511: 'Matrix Matrix::operator +(const Matrix &)' : overloaded member function not found in 'Matrix' ".

This is what I have for (+) operator in my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//the underline represents the red squiggly line in the IDE
Matrix Matrix::operator+(const Matrix &other) //overloading the + operator to bypass making a unique function for adding matrices
{
	//checks if condition for adding matrices is satisfied
	if( this->Rows != other.Rows ||
	    this->Cols != other.Cols)
	{
		std::cout << "\nAddition not possible because number of rows and columns differ between both matrices\n";
		return *this;
	}
	Matrix result("", Rows, Cols);
	for(int i = 0; i < Rows; i++) //adds element by element
	{
		for(int j = 0; j < Cols; j++)
		{
			result.pData[i][j] = this->pData[i][j] + other.pData[i][j];
		}
	}
	return result;
}


I don't understand what I did wrong for the syntax, and can't find anything online so far. Somebody can help?
Last edited on
closed account (Dy7SLyTq)
line five of the class def. you didnt give it any arguments
ah, of course. Thanks for the help. I been working on this program for so long today I didn't even realize something as simple as that was the problem.
closed account (Dy7SLyTq)
no problem. ive done worse
Topic archived. No new replies allowed.