please can any one remove the error coming in it

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
using namespace std;
class matrix
{
public:
	matrix(int sizeX,int sizeY);
	matrix();
	~matrix();
	matrix(const matrix& m);
	matrix operator+(const matrix& m);
	matrix& operator+=(const matrix& m);
	friend matrix operator*(const matrix& m1,const matrix& m2);
	friend ostream &operator<<(ostream &out,const matrix& m);
	friend istream &operator>>(istream &in,const matrix& m);
	int dx,dy;
	double **p;
private:
	
	void allocArrays()
	{
		p=new double*[dx];
		for(int i=0;i<dx;i++) 
		{
			p[i]=new double[dy]; 
		}
	}

	
};
matrix::matrix(int sizeX,int sizeY):dx(sizeX),dy(sizeY)
{
	allocArrays();
	for(int i=0; i<dx; i++)
	{
		for(int j=0; j<dy; j++)
		{
			p[i][j]=0;
		}
	}
}
matrix::matrix(const matrix& m):dx(m.dx),dy(m.dy)
{
	allocArrays();
	for(int i=0; i<dx; i++)
	{
		for(int j=0; j<dy; j++)
		{
			p[i][j]=m.p[i][j];
		}
	}
}
matrix::~matrix()
{
	for(int i=0; i<dx; i++)
	{
		delete [] p[i];
	}
	delete []p;
}
matrix& matrix::operator +=(const matrix& m)
{
	for(int i=0; i<dx; i++)
	{
		for(int j=0; j<dy; j++)
		{
			p[i][j]+=m.p[i][j];
		}
	}
	return *this;
}

matrix matrix::operator +(const matrix& m)
{
	matrix temp(*this);
	return (temp+=m);
}
ostream& operator<<(ostream &out, const matrix& m)
{
	for(int i=0; i<m.dx; i++)
	{
		for(int j=0; j<m.dy; j++)
			out<<m.p[i][j]<<" ";
		out<<endl;
	}
	return out;
}

matrix operator*(const matrix& m1,const matrix& m2)
{
	matrix prod(m1.dx,m2.dy);
	for(int i=0; i<prod.dx;i++)
	{
		for(int j=0; j<prod.dy; j++)
		{
			for(int k=0; k<m1.dy; k++)
			{
				prod.p[i][j]+=m1.p[i][k]*m2.p[k][j];
			}
		}
	}
	return prod;
}


int main()
{
	 matrix x(2,1);
	 cout<<x;
	return 0;
}
Last edited on
Could you post it as a code-block? It's very difficult to read like this.. ;P
what do u mean by code blocks? u can copy and paste it in ur compiler and can see the error.. i m not using the code blocks compiler. i m using visual c++
enclose the code in codeblock tags ["code"]["/code"] without the "
He's not talking about the IDE, but the formatting of the text :P
 
//This is what your code will look like if you use the [code][(backslash)code] tags. 


Look on the right of the input box. You'll see a bunch of format options. The first one is the code tags. Please stick any code between these two tags. Makes it much easier to read.
Last edited on
is it good enough?
bro i would be so thankful to u al if u can see why there is an error while overloading the stream operator <<
Huh?
It compiles and runs fine for me.
What does the error say exactly?
E:\cpp11.cpp(108) : error C2593: 'operator <<' is ambiguous
Are you using a really old compiler?

I just tested it using both MinGW and Microsoft Visual C++ 2010, and it compiled and ran fine in both.
ok let me try it on g++.. eclipse
Topic archived. No new replies allowed.