Yes. You created a pointer in your class. But that's it, it's a pointer.
What you are doing here -
1 2
|
for( int i=0; i < months ; i++)
cin >> p[i];
|
is using the pointer as an array, which for obvious reasons wont work. Not before you do this -
p=new int [months];
which creates a dynamic array of size months, and now you can do
cin >> pi[i];
. Your problem is that you try and do that before you create the array.
The array is created on line 31 in the
function constructor
Employee::Employee(int _ID, string _name, int _salary,int _months){
. You never call this
function
constructor and there fore the array is never created, that is why when you try to use the array in Set_Salary, it does not exist and doesn't work.
Hope this makes things more clear =)
Edit: Thanks @doug4 for the correction.