Two problems:
1. Don't pass function arguments by value, pass it by
const
reference instead. The only exceptions are (a) when it is a built-in type (
int
,
char
,
double
), or (b), if the parameter is meant for output (in which case it should be passed by reference, without
const
)
2. You've defined the variable to receive the number definition locally within the function, rather than as a class member variable.
Also, you can take advantage of the copy constructor of class
vector
and just initialize the entire
vector
in the initializer list without bothering with a loop:
class BigInteger {
std::vector<int> number_;
public:
BigInteger(const std::vector<int>& num) : number_(num) {}
};
P.S.: as Sergey pointed out in the comments, having such a constructor may be pointless: whenever you want to initialize a BigInteger, what you have is either a (decimal) text representation of a long number, or just a simple integer type. So you should provide constructors for those types instead.
The only reason to provide a constructor for a different type would be if you want to interface with another kind of big integer class - in which case the question arises why you need a second one.