I have the something like the following:
#include <vector>
#include <iostream>
template<typename T>
class Vector {
private:
std::vector<T> base;
public:
Vector(const std::vector<T> vec) {base = vec;}
T& operator[](const int& index) {return base[index];}
std::vector<T> getBase() const {return base;}
};
class BigNum : public Vector<int>
{
public:
BigNum(const std::vector<int> init) : Vector(init) {}
};
int main()
{
int arr[] = {6,3,7,6,2};
std::vector<int> v(arr, arr + sizeof(arr) / sizeof(arr[0]));
BigNum num(v);
for(auto it = num.getBase().begin(); it != num.getBase().end(); ++it)
{
std::cout << *it << " "; // What's going on here??
}
std::cout << "\n";
for(int i = 0; i < 5; ++i)
{
std::cout << num.getBase()[i] << " ";
}
std::cout << "\n";
}
The output of these two loops is:
30134336 0 7 6 2
6 3 7 6 2
What's going on here? The first number in the first loop (30134336) changes every time, but the remaining numbers are the same. Thanks in advance!