I was looking to learn some OOP concepts and i'm stuck with this error
#include <iostream>
using namespace std;
class Employee
{
private:
string name;
int salary;
public:
Employee()
{
name = "";
salary = 0;
}
int getSalary()
{
return salary;
}
};
int main()
{
Employee e1;
e1.getSalary() = 7000;
cout << e1.getSalary();
return 0;
}
From what I understood, if I add & to method getSalary()
it will be a setter and getter at the same time. I am confused why I need to add & to getSalary()
method to work properly. What's the point of reference in this case?
Aucun commentaire:
Enregistrer un commentaire