pHead->nBlockUse error

Hello, i have a problem and i need your help. In this code i'm trying to create 2 bidimensional arrays, and a third bidimensional array created from the sum of the others two. But when i try i get this error: "Debug Assertion Failed! Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)"
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include<iostream>
using namespace std;

class CTablou
{
private:
	int **t;
	int linii,coloane;//linii-lines coloane-columns
public:
	CTablou();
	CTablou(int, int );
	~CTablou();
	void SetTablou(int,int,int);
	void SetLinii(int);
	void SetColoane(int);
	int GetTablou(int,int);
	int GetLinii();
	int GetColoane();
	void creare();
	void creare(int,int);
	void afisare();
	void realocare(int,int);
	CTablou operator+(CTablou);
	//CTablou operator-(CTablou);
	//CTablou operator*(CTablou);
};

CTablou::CTablou()
{
	t=new int*[20];
	for(int i=0;i<20;i++)
			t[i]=new int[20];
	coloane=20;
	linii=20;
}

CTablou::CTablou(int n, int m)
{
	t=new int*[n];
	for(int i=0;i<n;i++)
			t[i]=new int[m];
	coloane=n;
	linii=m;
}

CTablou::~CTablou()
{
	for(int i=0;i<linii;i++)
		delete []t[i];
	t=NULL;
	coloane=0;
	linii=0;
}

void CTablou::SetTablou(int i,int j,int x)
{
	t[i][j]=x;
}

void CTablou::SetColoane(int j)
{
	coloane=j;
}

void CTablou::SetLinii(int i)
{
	linii=i;
}

int CTablou::GetTablou(int i,int j)
{
	return t[i][j];
}

int CTablou::GetColoane()
{
	return coloane;
}

int CTablou::GetLinii()
{
	return linii;
}

void CTablou::creare()
{//i create the array
	int x;
	for(int i=0;i<linii;i++)
		for(int j=0;j<coloane;j++)
		{
			cin>>x;
			SetTablou(i,j,x);
		}
}
void CTablou::creare(int n, int m)
{
	int x,i,j;
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		{
			cin>>x;
			t[i][j]=x;
		}
	for(i=n;i<linii;i++)
			delete []t[i];
	linii=n;
	coloane=m;
}

void CTablou::afisare()
{//i display it
	for(int i=0;i<linii;i++)
	{
		for(int j=0;j<coloane;j++)
			cout<<t[i][j]<<" ";
		cout<<endl;
	}
}

void CTablou::realocare(int n,int m)
{//i realocate memory for exemple from an array with [20][20] to [5][5]
	int i;
	for(i=0;i<linii;i++)
		delete []t[i];
	linii=n;
	coloane=m;
	t=new int*[n];
	for(i=0;i<linii;i++)
		t[i]=new int[coloane];
}

CTablou CTablou::operator +(CTablou mat)
{
	CTablou aux;
	int man,i,j;
	aux.realocare(mat.GetLinii(),mat.GetColoane());
	for(i=0;i<this->GetLinii();i++)
		for(j=0;j<this->GetColoane();j++)
		{
			man=this->GetTablou(i,j)+mat.GetTablou(i,j);
			aux.SetTablou(i,j,man);
		}
	return aux;
}
int main()
{
	CTablou a(2,2),b(2,2),c;
	a.creare();
	b.creare();
	cout<<endl<<endl;
	a.afisare();
	b.afisare();
	c=a+b;//and after this line i get that error
	c.afisare();
	return 0;
}
You need a copy constructor and a copy assignment operator.
http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29
Topic archived. No new replies allowed.