Debug Error

Hi ! can anynone ask me what to do! there is no errors in my code, but when it runs there is Debug error!
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
#include<iostream>
using namespace std;

class CNumber{
public:
	CNumber();
	void Get_Size();
	void array_create();
	void array_input();
	void miavorel();
	void output();
	~CNumber();
private:
	int Size_1;
	int Size_2;
	int *array_1;
	int *array_2;
	int *array_3;
	int n;
};
int main()
{
	CNumber number;
	number.Get_Size();
	number.array_create();
	number.array_input();
	number.miavorel();
	number.output();
	return 0;
}
CNumber::CNumber()
{
	Size_1=0;
	Size_2=0;
	array_1=NULL;
	array_2=NULL;
}
void CNumber::Get_Size()
{
	cout<<"Enter the size of array\n";
	cin>>Size_1;
	cout<<"Enter the size of array\n";
	cin>>Size_2;
}
void CNumber::array_create()
{
	array_1=new int[Size_1];
	array_2=new int[Size_2];
}
void CNumber::array_input()
{
	cout<<"Enter the array\n";
	for(int i=0;i<=Size_1;i++)
		cin>>array_1[i];
	cout<<"Enter the array\n";
	for(int j=0;j<=Size_2;j++)
		cin>>array_2[j];
}
void CNumber::miavorel()
{
	if(Size_1>Size_2)
		n=Size_1;
	else
		n=Size_2;
	
	array_3=new int[n];

	for(int i=0;i<=Size_1;i++)
	{
	for(int j=0;j<=Size_2;j++)
		for(int k=0;k<=n;k++)
			if(array_1[i]==array_2[j])
				array_3[k]=array_1[i];
			else
			{array_3[k]=array_1[i];
			array_3[k+1]=array_2[j];}
	}
}
void CNumber::output()
{
	for(int i=0;i<=n;i++)
		cout<<array_2[i]<<endl;
}
CNumber::~CNumber()
{
	delete [] array_1;
	delete [] array_2;
	delete [] array_3;
}
all these 3 functions have out of bounds access errors:
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
void CNumber::array_input()
{
	cout<<"Enter the array\n";
	for(int i=0;i<=Size_1;i++)
		cin>>array_1[i];
	cout<<"Enter the array\n";
	for(int j=0;j<=Size_2;j++)
		cin>>array_2[j];
}

void CNumber::miavorel()
{
	if(Size_1>Size_2)
		n=Size_1;
	else
		n=Size_2;
	
	array_3=new int[n];

	for(int i=0;i<=Size_1;i++)
	{
	for(int j=0;j<=Size_2;j++)
		for(int k=0;k<=n;k++)
			if(array_1[i]==array_2[j])
				array_3[k]=array_1[i];
			else
			{array_3[k]=array_1[i];
			array_3[k+1]=array_2[j];}
	}
}

void CNumber::output()
{
	for(int i=0;i<=n;i++)
		cout<<array_2[i]<<endl;
}


This destructor
1
2
3
4
5
6
CNumber::~CNumber()
{
	delete [] array_1;
	delete [] array_2;
	delete [] array_3;
}

has a delete error because in the constructor you set array_1 and array_2 to NULL, BUT array_3 is only a valid pointer if you call the miavorel function otherwise it is UNDEFINED.
Topic archived. No new replies allowed.