i have also overloaded << and >>...so dat dey can read and print d whole matrix at one statement..
the code of these overloaded operators is something like this..
Expand|Select|Wrap|Line Numbers
- // for >> (cin) :
- istream& operator >> (istream &read, matrix &mat)
- {
- for (int i = 0; i < mat.rows * mat.columns; ++i)
- read >> *(mat.element+i);
- return read;
- }
- // for << (cout) :
- ostream& operator << (ostream &print, matrix &mat)
- {
- for (int i = 0; i < mat.rows; ++i)
- {
- for (int j = 0; j < mat.columns; ++j)
- {
- print << *mat.element << " ";
- ++mat.element;
- }
- print << endl;
- }
- mat.element -= mat.rows * mat.columns;
- return print;
- }
matrix matrix1;
cin >> matrix1;
now...my question is :
wat if i want to pass a pointer variable which should be received by a reference...smthing like this...
Expand|Select|Wrap|Line Numbers
- main()
- {
- matrix *matrix2;
- cin >> matrix2; //i aint sure that this statement is right...it may be cin >> *matrix2...
- }
Expand|Select|Wrap|Line Numbers
- for >> :
- istream& operator >> (istream &read, matrix *&mat)
- {
- for (int i = 0; i < mat->rows * mat->columns; ++i)
- read >> *(mat->element+i);
- return read;
- }
- // for << :
- ostream& operator << (ostream &print, matrix *&mat)
- {
- for (int i = 0; i < mat->rows; ++i)
- {
- for (int j = 0; j < mat->columns; ++j)
- {
- print << *mat->element << " ";
- ++mat->element;
- }
- print << endl;
- }
- mat->element -= mat->rows * mat->columns;
- return print;
- }
however my problem is when i execute the program...then while taking input for a pointer matrix...it just reads one value instead of all the values..but doesnt even print that single value..
i think there must be bug in those overloaded functions used for pointer variable.. :(
so please check out the functions and post the solution or your suggestions...