I apologize if the question title doesn't effectively (or at all) reflect my actual question; this is my first time asking or answering on stackoverflow and may have goofed...
Anyway, my (elaborated) question is this:
When defining public member functions in a class that require use of private member variables, each of which (the private vars) having public member "getter" functions (please no answers saying "lose the getters/setters...", I'm using them), would it be better -- actually "better", like which makes the class more "extensible" between C++ compilers and which option allows for more "forward compatibility" -- to use this->m_variable OR to use this->getm_variable()?
I've included the following code example (creating a class named Family) from the project I am currently working on to try and clarify what exactly I mean:
Snippet of Family.h
private:
Person* children; // array of Person objects - Person is a member struct
size_t numChildren;
public:
enum gender { NONE = 0, MALE, FEMALE }
size_t countChildren() { return numChildren; }
size_t countChildren(gender g);
Person* getChild() { return children; }
Snippet of Family.cpp
// this is the specific function example:
size_t Family::countChildren(gender g) {
for (size_t i = 0; i < this->numChildren; i++) {
...CODE TO COUNT CHILDREN OF SPECIFIED GENDER...
}
return # of children with gender g // pseudocode, obviously...
}
So, now for the question changed for the example:
In the definition of the countChildren(gender g)
function where I have i < this->numChildren;
would it be better (in terms of the metrics I stated earlier) to use i < this->countChildren();
?
Similarly, when iterating through the children array for the same for loop, would it be better to define each Person*
in the current iteration using *(this->children + i)
OR to use *(this->getChild() + i);
?
Thank you in advance for any help and I apologize if this question is too "discussion-based" for stackoverflow, as I mentioned earlier, this is my first time asking a question.