super noob with pointers

okay so i'm taking an online class and i cant understand my teachers directions for sh*t, probably because i havent worked with c++ in awhile, nonetheless. I got some code, but its not workin the way i want. here are my teachers lame arse instructions:

Write a class that creates and populates an array of integers (any size) using a pointer. Make sure the constructor initializes and populates the array. In your main program output the contents of an object of this class by using the [] operator. You will have to overload the [] in the class. Also, show that you cannot output an array element that is out of bounds.


so idk what that means really but here is my code. Basically, why does line 32 change, since im adding one to userVal the line after. Plus if I switch line 32 and 33, my value is totally different. Can anyone explain.


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

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

class intAr	 
{	 	 //writing defintion of our class {
public:
	intAr();	 	 //constructors
	
	
	int *userVal;
	int arDim;
	int i;
};

intAr::intAr ()	  	  //defining constructors
{
i=0;
cout<<"Enter the number of integers you would like to enter:";
cin>>arDim;
userVal = new int[arDim];

while (i<arDim)
{


cout<<endl<<"Enter an integer:";
cin>>*userVal;
cout<<userVal[0];
userVal+=1;


i++;





}


}





int main()			//main function
{
	intAr list1 = intAr();	  //declaring object date1 of class Date
	
	
	
	
	return 0;
}

Topic archived. No new replies allowed.