问题描述:
友元函数使形参是2个以上,若只是运算符重载参数为一个,或者使用inline
#ifndef MATRIX_H_
#define MATRIX_H_
#include <vector>
#include <iostream>
using namespace std;
typedef float elemType;
class Matrix
{
friend Matrix operator+(const Matrix & ,const Matrix & );
friend Matrix operator*(const Matrix & ,const Matrix & );
//此处
public:
Matrix(const elemType*);
Matrix(elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.,
elemType=0.,elemType=0.,elemType=0.,elemType=0.);
int rows() const{ return 4;};
int cols() const{ return 4;};
ostream& print(ostream& )const;
void operator+=(const Matrix&);
elemType operator()(int row,int col)const{return _matrix[row][col];};
elemType& operator()(int row,int col){return _matrix[row][col];};
//此处是下标运算!
private:
elemType _matrix[4][4];
};
inline ostream & operator<<(ostream& os,const Matrix &m){return m.print(os);};
//此处
#endif