Error in codes

Page 1 of 1

1 Replies - 9374 Views - Last Post: 12 January 2013 - 04:39 PM

#1 unknownmaster80  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 11

Error in codes

Posted 12 January 2013 - 04:36 PM

Main class
#include "List.h"
#include "Worker.h"
#include <iostream>
#include <string>

using namespace std;
void initWorkerList(List<Worker>);

int main() {
    List<Worker> WorkerList;
    initWorkerList(WorkerList);

    string username, password;
    cout << "Please enter your username: " << endl;
    getline(cin, username);
    cout << "Please enter your password: " << endl;
    getline(cin, password);

    Worker w;
    bool success = w.login(username,password, WorkerList);
    if(success) {
             // code

    } else {
        cout << "Invalid username and/or password. \nPlease try again!";
    }

    system("pause");
    return 0;
}

void initWorkerList(List<Worker> WorkerList) {
    Worker w1 = Worker("Ben Ang", "Ben123", "pass123", 'M');
    WorkerList.add(w1);
    Worker w2 = Worker("Grace Eng", "Gr4ce", "loveGrace", 'W');
    WorkerList.add(w2);
    Worker w3 = Worker("Rebecca Xuan", "Xuanz", "Rebecca Xuan", 'W');
    WorkerList.add(w3);
}

Worker class

#include <string>
#include "List.h"
using namespace std;
class Worker {
private:
    string name;
    string username;
    string password;
    char position;
public:
    Worker();
    Worker(string, string, string, char);
    string getName();
    string getUserName();
    string getPassword();
    char getPosition();
    bool login(string, string, List<Worker>);
};

Worker::Worker() {  
}

Worker::Worker(string n, string un, string pw, char p) {
    name = n;
    username = un;
    password = pw;
    position = p;
}

string Worker::getName() {
    return name;
}

string Worker::getUserName() {
    return username;
}

string Worker::getPassword() {
    return password;
}

char Worker::getPosition() {
    return position;
}

bool login(string username, string password, List<Worker> WorkerList) {
    string u, pw;
    for(int i =0; i<WorkerList.length(); i++) {
        Worker w = WorkerList.get(i);
        u = w.getUserName();
        pw = w.getPassword();
        if(username == u && password == pw) {
            return true;
        }
    }
    return false;
}

List class

#include <iostream>
using namespace std;

const int MAX_SIZE = 20;

template <typename ItemType>
class List {
private:
    ItemType itemList[MAX_SIZE];
    int size;
public: 
    List();
    void add(ItemType);
    void del(int index);
    bool isEmpty();
    ItemType get(int);
    int length();
};


template<typename ItemType>
List<ItemType>::List() {
    size = 0;
}

template<typename ItemType>
void List<ItemType>::add(ItemType item) {
    if(size < MAX_SIZE) {
        itemList[size] = item;
        size++; 
    } 
    else {
        cout << "List is full.\n";
    }
}

template<typename ItemType>
void List<ItemType>::del(int index) {
    if(!isEmpty()) {
        if(index > 0 && index < size) {
            for(int i = index + 1; i <= size; i++) {
                itemList[i-2] = itemList[i-1];
            }
            size--;
        }
    } else {
        cout << "List is empty.\n";
    }
}

template<typename ItemType>
bool List<ItemType>::isEmpty() {
    return size == 0;
}

template<typename ItemType>
ItemType List<ItemType>::get(int index) {
    if(index > 0 && index <= size) 
        return itemList[index-1];
}

template<typename ItemType>
int List<ItemType>::length() {
    return size;
}

These are my errors
Error 11 error C2133: 'WorkerList' : unknown size c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 18 1 DSA_Assignment Error 4 error C2244: 'List::add' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 35 1 DSA_Assignment Error 5 error C2244: 'List::del' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 49 1 DSA_Assignment Error 7 error C2244: 'List::get' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 60 1 DSA_Assignment Error 6 error C2244: 'List::isEmpty' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 54 1 DSA_Assignment Error 8 error C2244: 'List::length' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 65 1 DSA_Assignment Error 3 error C2244: 'List::List' : unable to match function definition to an existing declaration c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 24 1 DSA_Assignment Error 1 error C2370: 'MAX_SIZE' : redefinition; different storage class c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 4 1 DSA_Assignment Error 12 error C2512: 'List' : no appropriate default constructor available c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 18 1 DSA_Assignment Error 14 error C2512: 'List' : no appropriate default constructor available c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 19 1 DSA_Assignment Error 18 error C2662: 'List::add' : cannot convert 'this' pointer from 'List' to 'List &' c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 137 1 DSA_Assignment Error 19 error C2662: 'List::add' : cannot convert 'this' pointer from 'List' to 'List &' c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 139 1 DSA_Assignment Error 20 error C2662: 'List::add' : cannot convert 'this' pointer from 'List' to 'List &' c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 141 1 DSA_Assignment Error 10 error C2662: 'List::get' : cannot convert 'this' pointer from 'List' to 'List &' c:\users\user\dropbox\dsa_assignment\dsa_assignment\worker.h 49 1 DSA_Assignment Error 9 error C2662: 'List::length' : cannot convert 'this' pointer from 'List' to 'List &' c:\users\user\dropbox\dsa_assignment\dsa_assignment\worker.h 48 1 DSA_Assignment Error 15 error C2664: 'initWorkerList' : cannot convert parameter 1 from 'List' to 'List' c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 21 1 DSA_Assignment Error 17 error C2664: 'Worker::login' : cannot convert parameter 3 from 'List' to 'List' c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp 36 1 DSA_Assignment Error 2 error C2953: 'List' : class template has already been defined c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h 18 1 DSA_Assignment


Anyone knows the error? Especially the one on error C2133: 'WorkerList' : unknown size , C2953: 'List' : class template has already been defined and C2662: 'List::add' : cannot convert 'this' pointer from 'List' to 'List &' ? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Error in codes

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,246
  • Joined: 27-December 08

Re: Error in codes

Posted 12 January 2013 - 04:39 PM

Duplicate thread closed. I moved your other thread out of the Advanced Discussion forum because it isn't for help questions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1