Good evening everyone,
This next exercise, I have to do the following:
Write a ClassTemplate for a linked list. Demonstrate it by using two linked lists. The datafield of the first type is int, the second one is double.
What Ive got sofar is this:
#include <iostream>
#include <vector>
using namespace std;
template <class T>
class vec
{
public:
vec(T xx = 0, T yy = 0, T zz = 0): x(xx), y(yy), z(zz){} // Constructor.
void linklist(T &x, T &y, T &z);
void print() const;
private:
T x, y, z;
};
template <class T>
void vec<T>::print() const
{
cout<< x << " " << y << " " << z <<endl;
}
template <class T>
void vec<T>::linklist(T &x, T &y, T &z)
{
??????????
}
int main()
{
vec <int> a(1), b(4), c(9), ilist;
vec <double> d(4.5), e(9.7), f(0.3), dlist;
linklist(a, b, c);
linklist(d, e, f);
return 0;
}
I don't think it really is good, that's why I wanted to ask if someone could point me in the correct direction.
I think I have to use the template <vector>, but, how do I combine that with the template class?????