I have two methods:
bigint& bigint::operator=(const bigint& b){
init();
for(int i = N-1; i >= N - b.getLength(); i--){
un[i] = b.un[i];
}
setLength(b.getLength());
return *this;
}
void bigint::init(){
int L = getLength();
for(int i = 0; i < L; i++){
un[N-L+i] = 0;
}
setLength(1);
}
First is called operator=
in the code, which assigns value of b
to *this
.
Class bigint
represents big integers of max length = N. Instance of bigint
contains array of length equal to N
.
What's my problem:
I can't determine why calling the method init()
, which zeros every element of *this
, influences also the parametr b
.
It seems like it zeros also the b
.
When I delete the init()
calling from the operator=
method, b
is not modified, but I need to zero the bigint *this
before assigning it some value.
I don't understand what's really going on.
Thanks for any help.