Help with template function swap

I have a program with a double-list class and we are supposed to add a template function swap to, that should swap anything(including members of the class). I understand the concept of swapping ints and things of that nature, but I'm confused on how to approach this. I need help quick. He assigned it yesterday and it is due at midnight tonight. Here is some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class NumberList
{
  private:
    double *list;
    int numElements;
    bool isValid(int) const;
    bool isInOrder(int) const

  public:
    NumberList(int);
    NumberList();
    ~NumberList();
    void setElement(int, double);
    double getElement(int) const;
    double getHighest() const;
    double getLowest() const;
    double getAverage() const;
};



1
2
3
4
5
6
int main()
{
  const int SIZE = 3;
  NumberList numbers(SIZE);
  int val, x;
  ...


1
2
3
4
5
6
7
8
9
template <class T>
void swapVars(T &var1, T &var2)
{
  T temp;

  temp = var1;
  var1 = var2;
  var2 = temp;
}


Thanks for any help.

swapVars should work fine. What exactly is the problem ?
Last edited on
Topic archived. No new replies allowed.