Declaring a container member in a class does not make the class a container, nor does it create a container for the class.
Your
LongNumber class does not have a member called
container. You have to either write an accessor function:
class LongNumber
{
private:
vector<int> number;
public:
vector<int>& container();
};
ostream & operator <<(ostream & os, LongNumber & along)
{
for(std::vector<int>::iterator i = along.container().begin(); i != along.container().end(); ++i)
or make it a public member:
class LongNumber
{
public:
vector<int> number;
};
ostream & operator <<(ostream & os, LongNumber & along)
{
for(std::vector<int>::iterator i = along.number.begin(); i != along.number.end(); ++i)
or provide access to the beginning and end iterators:
class LongNumber
{
private:
vector<int> number;
public:
vector<int>::iterator begin()
{
return number.begin();
}
vector<int>::const_iterator begin() const
{
return number.begin();
}
vector<int>::iterator end()
{
return number.end();
}
vector<int>::const_iterator end() const
{
return number.end();
}
};
ostream & operator <<(ostream & os, LongNumber & along)
{
for(std::vector<int>::iterator i = along.begin(); i != along.end(); ++i)
Note that I've changed the type in the loop from
std::vector<LongNumber> to
std::vector<int> here. The code in the examples above will iterate over the elements of the member container of your
along variable.