Deleting element from arra

I am getting this error in following program.What is wrong in this?
task_constructor.cpp:18:7: error: expected unqualified-id before ‘delete’
task_constructor.cpp:49:1: error: expected ‘}’ at end of input
task_constructor.cpp:17:2: error: expected unqualified-id at end of input
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
//Following program asks the user to enter 5 elements , store them in a dta member of class array
//it then asks the user to enter the position from where he wants to remove the element,
//Then it removes the element and display the result.
#include<iostream>
using namespace std;
class array
{
	int arr[5],n;
public:
	array()
	{n=5;}
	array(int *element)
	{
		n=5;
		for(int i=0;i<5;i++)
			arr[i]=*(element+i);		
	}
	void delete(int position)
	{
		n=4;
		while(position<5)
		{
			arr[position]=arr[position+1];
			position++;
		}
	}
	void display()
	{
		for(int i=0;i<n;i++)
			cout<<a[i];
		cout<<endl;
	}
};
int main()
{
	int arr1[5];
	int position;
	cout<<"Enter 5 elements to be inserted into an array: ";
	for(i=0;i<5;i++)
		cin>>arr1[i];
	array a1(arr);
	cout<<"Elements entered by you are: \n";
	a1.display();
	cout<<"Enter the position from where you want to remove the element: ";
	cin>>position;
	a1.delete(position);
	a1.display();
return 0;
}


Thankyou for reading!
Last edited on
Line 18: delete is a reserved word.
Line 30: a is not defined. You need to pass it as an argument.
Line 39: Loop variable i is not defined.
Line 41: arr is not defined. Did you mean arr1?
Last edited on
Thank you..
I got it..
Its working fine now.
Topic archived. No new replies allowed.