Z
zfareed
Is it possible to print an array that is declared from a class type
that also contains private data members?
I have declared an array in the main function and then set the values
for the array thru member functions. Now I need to print the array
from main but the error states that those elements are private. Here
is some of my code:
class Employee
{
private:
int age;
int id;
float salary;
public:
void setAge(int x);
void setId(int x);
void setSalary(float x);
};
//the main is in the driver file
int main()
{
Employee arr[2];
arr[0].setAge(30);
arr[0].setId(30042554);
arr[0].setSalary(50000.00);
arr[1].setAge(45);
arr[1].setId(40041002);
arr[1].setSalary(70000.00);
PrintEmployee(arr,2); //-------------------states that
Employee::id is private
system("pause");
return 0;
}
//this is one member function included in the
void Employee::setAge() int x
{
arr.age = x;
return x;
}
that also contains private data members?
I have declared an array in the main function and then set the values
for the array thru member functions. Now I need to print the array
from main but the error states that those elements are private. Here
is some of my code:
class Employee
{
private:
int age;
int id;
float salary;
public:
void setAge(int x);
void setId(int x);
void setSalary(float x);
};
//the main is in the driver file
int main()
{
Employee arr[2];
arr[0].setAge(30);
arr[0].setId(30042554);
arr[0].setSalary(50000.00);
arr[1].setAge(45);
arr[1].setId(40041002);
arr[1].setSalary(70000.00);
PrintEmployee(arr,2); //-------------------states that
Employee::id is private
system("pause");
return 0;
}
//this is one member function included in the
void Employee::setAge() int x
{
arr.age = x;
return x;
}