I heard that in C ++, using accessor ( get...()) in a member function of the same class where accessor was defined is good programming practice? Is this true, and is it necessary to do this?
For example, this is preferable:
void display() {
cout << getData();
}
over something like this:
void display() {
cout << data;
}
datais a data member of the same class where the accessor was defined ... the same method display().
I think about the overhead for this, especially if you need to repeatedly call an accessory within the same class, and not just use the data element directly.
source
share