Thread: Down to One Error

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Martin, Tn
    Posts
    12

    Down to One Error

    OK I been workin on this prog for the last 4 hours or so...I got it down to one last error...Its 5am and I cant find what the problem is, I am hoping a fresh set of eyes will see the error.

    Code:
    Line #   Statement
    ------   ---------
     0001    using namespace std;
     0002    #include "List.h"
     0003    #include <cassert>
     0004    #include <iostream>
     0005    template <class T> List<T>::List()
     0006      { 
     0007        current_size = 0;
     0008      }
     0009    
     0010    //====================================================
     0011    template <class T> List<T>::List(const List &l)
     0012    {
     0013     int i;
     0014     for (i = 0; i < l.current_size; i++)
     0015        data[i] = l.data[i];
     0016     current_size = l.current_size;
     0017    }
     0018    
     0019    //====================================================
     0020    template <class T> int List<T>::get_size() const
     0021    {
     0022     return current_size;
     0023    }
     0024    
     0025    //====================================================
     0026    List &List::operator=(const List &l)
     0027    {
     0028     int i;
     0029     for (i = 0; i < l.current_size; i++)
     0030        data[i] = l.data[i];
     0031     current_size = l.current_size;
     0032     return *this;
     0033    }
     0034    
     0035    //====================================================
     0036    template <class T> T &List<T>::operator[](int index)
     0037    {
     0038      assert(index >= 0 && index < current_size);
     0039      return data[index];
     0040    }
     0041    
     0042    //====================================================
     0043    template <class T> bool List<T>::append(const T &item)
     0044    {
     0045     if (current_size < CAPACITY)
     0046       {
     0047         data[current_size] = item;
     0048         current_size++;
     0049         return true;
     0050       }
     0051     else
     0052        return false; 
     0053    }
     0054    
     0055    //====================================================
     0056    template <class T> void List<T>::traverse(void process(const T &item))
     0057    {
     0058     for (int i = 0; i < current_size; i++)
     0059       process(data[i]);
     0060    }
     0061    
     0062    //====================================================
     0063    template <class T> bool List<T>::insert(const T &item, int pos)
     0064    {
     0065     if(pos < 0 || pos > current_size || pos >= CAPACITY)
     0066        return false;
     0067     else
     0068       {
     0069        for(int i = current_size;i > pos ; i--)
     0070           data[i] = data[i-1];
     0071        data[pos] = item;
     0072        current_size++;
     0073        return true;
     0074       }
     0075    }
     0076    
     0077    //====================================================
     0078    template <class T> bool List<T>::erase(int pos)
     0079    {
     0080     if (pos < -0 || pos >= current_size)
     0081        return false;
     0082     else
     0083       {
     0084        for (int i = pos;i < current_size; i++)
     0085           data[i] = data[i+1];
     0086        current_size--;
     0087        return true;
     0088      }
     0089    }
     0090    
     0091    //====================================================
     0092    template <class T> void List<T>::print()
     0093    {
     0094     for (int i=0; i<current_size; i++)
     0095         cout << data[i] << endl;
     0096    }
     0097    
     0098    //=================== MAIN ===========================
     0099    //====================================================
     0100    int main(void)
     0101    {
     0102    int index;
     0103    
     0104    List<int> intlist;
     0105    intlist.insert (10,0);
     0106    intlist.insert (20,0);
     0107    intlist.insert (30,2);
     0108    intlist.insert (40,1);
     0109    intlist.erase (2);
     0110    cout << "Integer List" << endl;
     0111    intlist.print();
     0112    
     0113    List<float> floatlist;
     0114    floatlist.insert (1.5,0);
     0115    floatlist.insert (2.3,0);
     0116    floatlist.insert (1.5,0);
     0117    floatlist.erase (2);
     0118    floatlist.insert (6.5,0);
     0119    floatlist.insert (7.2,4);
     0120    floatlist.erase (0);
     0121    cout << "Float LisT" << endl;
     0122    floatlist.print();
     0123    
     0124    return 0;
     0125    }
    
    --- Compiling List.cpp...
    
    List.cpp:26: error: expected constructor, destructor, or type conversion before '&' token
    List.cpp:26: error: expected `,' or `;' before '&' token
    
    --- Compilation failed...
    
    --- No execution.
    There is the error at the bottom,I dont really understand what it is saying but I am expecting it to be something simple, If you can find the prob I would greatly appreciate it.

    Thanx in Advance..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > OK I been workin on this prog for the last 4 hours or so...I got it down to one last error...Its 5am and I cant find what the problem is
    Try some sleep - it works wonders.

    In the mean time, consider why that is the only function which lacks a
    template <class T> T
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM