friend function for overloading increment operator

I have a class matrix and I want to overload the increment operator using a friend function; however, I believe my syntax is wrong.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 *  matrix.h
 *
 */

#ifndef MATRIX_H
#define MATRIX_H
#include <vector>
#include <iostream>
using namespace std;

class matrix 
{
	vector<vector<int> > rows;
	int length;
	static int default_length;
 public:
	friend matrix operator+(const matrix &one, const matrix &two);
	friend matrix operator-(const matrix &one, const matrix &two);
	friend matrix operator*(const matrix &one, const matrix &two);
	friend matrix operator++();
	friend matrix operator--();
	friend ostream& operator<<(ostream &out, const matrix &one);
	matrix (int length  = 0);
	void addRow (int row, vector<int> columns);
};

#endif 


Here is my error message

matrix.h:21: error: ‘matrix operator++()’ must take either one or two arguments
matrix.h:22: error: ‘matrix operator--()’ must have an argument of class or enumerated type
matrix.h:22: error: ‘matrix operator--()’ must take either one or two arguments
matrix.h:21: error: ‘matrix operator++()’ must have an argument of class or enumerated type
matrix.h:21: error: ‘matrix operator++()’ must take either one or two arguments
matrix.h:22: error: ‘matrix operator--()’ must have an argument of class or enumerated type
matrix.h:22: error: ‘matrix operator--()’ must take either one or two arguments

What am I doing wrong?
Why not make your increment and decrement operators member functions rather than free friend functions? What does it mean to increment a matrix?
Thank you for responding to my post. I want to make them friend functions, because my homework explicitly requires me to define increment and decrement operation as friend functions. Incrementing a matix means incrementing each element in the matrix by one.
In that case, the operator has to take one parameter if it is a pre-increment operator and two if it is a post-increment operator. The first parameter is a reference to the object and the second (for post-increment/decrement) is an unused int.
dunsondog109 wrote:
I want to make them friend functions, because my homework explicitly requires me to define increment and decrement operation as friend functions.


Ew, that's really dumb IMO, but I guess you can't do anything about it.

Since you are overloading the global operator, you need to tell it what it is working on, like + and -. e.g.

1
2
friend matrix& operator++(matrix&); //prefix
friend matrix operator++(matrix&, int); //postfix 
Thankyou guys!
Topic archived. No new replies allowed.