You could ... but getters and setters are terms specifically used in pairs to allow encapsulation of your variables within a class.
Unlike C#, C++ doesn't support properties directly, so the name prefixes "get" and "set" are conventionally used to help the reader understand what is going on.
class Employee
{
private:
int salary;
public:
void setSalary(int s) { salary = s; }
int getSalary() { return salary; }
}
...
myEmployee.setSalary(56000);
int x = myEmployee.getSalary();
In C# it's a little more elegant, and you use the property as if it was a variable instead of calling functions directly:
class Employee
{
private int salary;
public int Salary
{
get { return salary; }
set {salary = value; }
}
};
...
myEmployee.Salary = 56000;
int x = myEmployee.Salary;
Or even:
class Employee
{
public int Salary { get; set; }
};
...
myEmployee.Salary = 56000;
int x = myEmployee.Salary;
And the backing variable will be handled automatically.