I am trying to implement my own OrderedList data structure using class templates. Each constructor and function in my CPP file has an error on the opening '{'. The error reads "redefinition of FUNCTION_NAME FUNTION_NAME previously declared here".
I've had a few colleagues look at it, but to no avail. Here are my files and the error:
CPP FILE "MyOrderedList.cpp"
#include "MyOrderedList.h"
template <class E>
MyOrderedList<E>::MyOrderedList() {/*IMPLEMENTATION*/}
template <class E>
MyOrderedList<E>::MyOrderedList(const MyOrderedList<E>& orig) { /*IMPLEMENTATION*/}
template <class E>
void MyOrderedList<E>::operator =(const MyOrderedList<E>& orig){/*IMPLEMENTATION*/}
template <class E>
MyOrderedList<E>::~MyOrderedList() {/*IMPLEMENTATION*/}
template <class E>
void MyOrderedList<E>::insert(E data){/*IMPLEMENTATION*/}
template <class E>
E MyOrderedList<E>::get(int pos) const{/*IMPLEMENTATION*/}
template <class E>
Node<E>* MyOrderedList<E>::getHead() const{/*IMPLEMENTATION*/}
template <class E>
MyOrderedList<E> MyOrderedList<E>::kLargest(int k) const{/*IMPLEMENTATION*/}
template <class E>
MyOrderedList<E> MyOrderedList<E>::operator +(const MyOrderedList<E>& list {/*IMPLEMENTATION*/}
H FILE "MyOrderedList.h"
#ifndef MYORDEREDLIST_H
#define MYORDEREDLIST_H
#include <iostream>
#include <cstdlib>
#include "Node.h"
template <class E>
class MyOrderedList;
template <class E>
std::ostream& operator <<(std::ostream& out, const MyOrderedList<E>& list);
template <class E>
class MyOrderedList {
public:
MyOrderedList();
MyOrderedList(const MyOrderedList<E>& orig);
void operator =(const MyOrderedList<E>& orig);
virtual ~MyOrderedList();
bool remove(E data);
MyOrderedList<E> kLargest(int k) const;
E get(int pos) const;
void insert(E data);
Node<E>* getHead() const;
MyOrderedList<E> operator +(const MyOrderedList<E>& list);
friend std::ostream& operator <<(std::ostream& out, const MyOrderedList<E>& list){/*IMPLEMENTATION*/}
private:
Node<E>* head;
int size;
};
#include "MyOrderedList.cpp"
#endif //MYORDEREDLIST_H
Node.h
#ifndef NODE_H
#define NODE_H
#include <iostream>
template <class E>
class Node {
public:
Node(const E& init_data = NULL, Node<E>* init_link = NULL){data = init_data; link = init_link;}
Node(const Node<E>& orig);
virtual ~Node();
E getData() const{return data;}
void setData(E newData);
Node<E>* getLink(){return link;}
void setLink(Node<E>* nextLink) {link = nextLink;}
private:
E data;
Node<E>* link;
};
#endif /* NODE_H */
Compiler Errors
MyOrderedList.cpp:12: error: redefinition of `MyOrderedList<E>::MyOrderedList()'
MyOrderedList.cpp:12: error: `MyOrderedList<E>::MyOrderedList()' previously declared here
MyOrderedList.cpp:19: error: redefinition of `MyOrderedList<E>::MyOrderedList(const MyOrderedList<E>&)'
MyOrderedList.cpp:19: error: `MyOrderedList<E>::MyOrderedList(const MyOrderedList<E>&)' previously declared here
MyOrderedList.cpp:42: error: redefinition of `void MyOrderedList<E>::operator=(const MyOrderedList<E>&)'
MyOrderedList.cpp:42: error: `void MyOrderedList<E>::operator=(const MyOrderedList<E>&)' previously declared here
MyOrderedList.cpp:77: error: redefinition of `MyOrderedList<E>::~MyOrderedList()'
MyOrderedList.cpp:77: error: `virtual MyOrderedList<E>::~MyOrderedList()' previously declared here
MyOrderedList.cpp:91: error: redefinition of `void MyOrderedList<E>::insert(E)'
MyOrderedList.cpp:91: error: `void MyOrderedList<E>::insert(E)' previously declared here
MyOrderedList.cpp:119: error: redefinition of `E MyOrderedList<E>::get(int) const'
MyOrderedList.cpp:119: error: `E MyOrderedList<E>::get(int) const' previously declared here
MyOrderedList.cpp:134: error: redefinition of `Node<E>* MyOrderedList<E>::getHead() const'
MyOrderedList.cpp:134: error: `Node<E>* MyOrderedList<E>::getHead() const' previously declared here
MyOrderedList.cpp:140: error: redefinition of `MyOrderedList<E> MyOrderedList<E>::kLargest(int) const'
MyOrderedList.cpp:140: error: `MyOrderedList<E> MyOrderedList<E>::kLargest(int) const' previously declared here
MyOrderedList.cpp:158: error: redefinition of `MyOrderedList<E> MyOrderedList<E>::operator+(const MyOrderedList<E>&)'
MyOrderedList.cpp:158: error: `MyOrderedList<E> MyOrderedList<E>::operator+(const MyOrderedList<E>&)' previously declared here