vector<int> v_i;
vector<double> v_d;
vector<Employee> v_e;
template<typename T>
class Pair {
public:
Pair(T a, T b);
T get_first() const;
T get_second() const;
private:
T first;
T second;
};
Syntax 17.3: Template Class Definition template<typename type_variable>
|
template<typename T>
Pair<T>::Pair(T a, T b)
{ first = a;
second = b;
}
template<typename T>
T Pair<T>::get_first() const
{ return first;
}
template<typename T>
T Pair<T>::get_second() const
{ return second;
}
Syntax 17.4: Template Member Function Definition template<typename type_variable>
|
template<typename T> |
class List { |
template<typename T>
Iterator<T> List<T>::begin()
{ Iterator<T> iter;
iter.position = first;
iter.position = last;
return iter;
}
list<string>::iterator pos = staff.begin();
vector<double>::iterator p = a.begin();
list<string>::iterator q = b.begin();
class List {
...
class Iterator;
...
};
Syntax 17.5 : Nested Class Declaration class Outer_class_name
|
List::Iterator::Iterator()
{
...
}
string List::Iterator::get() const
{
...
}