G
gallows
The container is:
template <typename T>
class Container {
public:
// container methods..
// iterator:
class const_iterator {
public:
const_iterator(T* i)
: pntr(i) { }
const_iterator& operator=
(const_iterator);
const_iterator& operator++();
const_iterator operator++(const_iterator);
const_iterator& operator--();
const_iterator operator--(const_iterator);
bool operator==(const_iterator);
bool operator!=(const_iterator);
private:
T* pntr;
};
const_iterator begin() const;
const_iterator end() const;
private:
std::vector<T> v;
};
// Well... implementation for Container<T>::begin() :
template <typename T>
Container<T>::const_iterator Container<T>::begin() const
{
const_iterator i(&v[0]);
return i;
}
g++ says: "error: expected constructor, destructor, or type conversion
before 'Container'"
Where is it wrong? Which is the right way to do that?
Thanks in advance,
s.
template <typename T>
class Container {
public:
// container methods..
// iterator:
class const_iterator {
public:
const_iterator(T* i)
: pntr(i) { }
const_iterator& operator=
(const_iterator);
const_iterator& operator++();
const_iterator operator++(const_iterator);
const_iterator& operator--();
const_iterator operator--(const_iterator);
bool operator==(const_iterator);
bool operator!=(const_iterator);
private:
T* pntr;
};
const_iterator begin() const;
const_iterator end() const;
private:
std::vector<T> v;
};
// Well... implementation for Container<T>::begin() :
template <typename T>
Container<T>::const_iterator Container<T>::begin() const
{
const_iterator i(&v[0]);
return i;
}
g++ says: "error: expected constructor, destructor, or type conversion
before 'Container'"
Where is it wrong? Which is the right way to do that?
Thanks in advance,
s.