I have been trying to figure this out for now 4 hours. And I just can't find it, I give up. I have to create a class where I store the digits of large numbers in a vector. And I also have to create functions for them. One of them is for multiplying. I know this isn't how you multiply a large number, this is just a test function for it. But it doesnt work. It doesn't give errors, the program just waits for a while, then prints nothing (I print it in main). I have already created classes many times, and they worked, and their functions returned their types perfectly. The only way this is working for me is like this:
largeNum mul(int x){
for(int i=0; i<_numArr.size(); i++){
_numArr[i] = _numArr[i] * x;
}
return *this;
}
But I dont want to overwrite my original vector. I want to give the result to a new largeNum type object's vector. I tried pointers with it in every way, and its just not working. Maybe because it's 3 AM, but I'm not getting anywhere. This is what i'm trying with:
class largeNum{
public:
std::vector<int> _numArr;
public:
largeNum(){
for(int i=0; i< _numArr.size(); i++){
_numArr[i]=0;
}
}
largeNum mul(int x){
largeNum res;
for(int i=0; i<_numArr.size(); i++){
res._numArr[i] = _numArr[i] * x;
}
return res;
}
}
/* the printing part in main.cpp:
largeNum b = n1.mul(2);
for(int i=0; i < b._numArr.size(); i++){
cout << b._numArr[i] << endl;
}
*/
Please help.