I want to use a class in C++ that has an integer array like this:
class A{
private:
int arr[50];
}
I will read something from text file like this:
sum i1 i2
That means: Sum of arrays index1 and index2 and store in index1.
How can I do it, with using getters and setters like:
seti2(geti1()+geti2())
or something like that, (because it's not very useful, I don't want to write getter and setter for every index geti1() geti2() ... geti50())
Do you have any idea?
By the way, my second question is that, is getter should not have any parameters and is setter should have only one parameter?
One idea might be to use actual indexes. So you have a single get
function which takes an index as an argument, and a single set
function which takes an index and the value as arguments.
Another solution is to overload the operator[]
function, to provide nice array-like indexing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With