Complete Project 4 from Chapter 6 of the text. Directions are on page 347.
// referencing (forward) declaration:
template <class K, class V>
class const_iterator;
template <class K, class V>
class keyed_bag4 {
//...
};
template <class K, class V>
class const_iterator
: public std::iterator<std::forward_iterator_tag, K, V> {
// ...
};
#include "keyed_bag4.cpp"
keyed_bag4();
keyed_bag4(const keyed_bag4& source);
~keyed_bag4();
keyed_bag4& operator =(const keyed_bag4& source);
void insert(const V& entry, K key);
bool erase(K key);
V get(K key) const throw(std::invalid_argument);
size_type size() const;
size_type count(const V& target) const;
bool has_key(K key) const;
const_iterator<K, V> begin() const;
const_iterator<K, V> end() const; // hint: should position cursor just
// past the end of the pair array
const_iterator(const std::pair<K, V>* initial = NULL);
const_iterator& operator ++();
const_iterator operator ++(int);
bool operator !=(const const_iterator item) const;
bool operator ==(const const_iterator item) const;
const std::pair<K, V> operator*();
When you're satisfied with the definition and implementation, submit your work via the CATE form for Project E.
Legend: method/function keyword literal
2008/03/11