I am learning, so it is probably something trivial. The length should be 2 (call down below), but I get 4 in the output. Can someone tell me my mistake?
BigInt::BigInt(const unsigned short int ip[])
: is_negative(false), length(sizeof(ip) / sizeof(ip[0])), digits(new unsigned short[sizeof(ip) / sizeof(ip[0])]) {
// assumption: this case is alway is_negative = false (array of short int to BigInt)
cout << "length is " << length << endl;
for (int i = 0; i < length; i++) {
digits[i] = ip[i];
}
cout << "made from int arr of length "<< length << "--" << (sizeof(ip) / sizeof(ip[0])) << endl;
}
Called from main:
void test_cmp() {
cout << "---- ---- ---- cmp val ---- ---- ----" << endl;
BigInt i1(33290); // default arguments
//DEBUG(i1);
BigInt i2(33299);
unsigned short int ip[] = { 1,2 };
cout << "unsgined short array size" << sizeof(ip)/sizeof(ip[0]) << endl;
BigInt i3(ip);
short cmpval = i1.cmp(i3);
cout << "cmp val" << cmpval << endl;
}