Hey everyone I'm trying to do a program where I overload operators such as *, +, / etc. so that I can add/multiply/subtract vectors/lists from each other and add numbers to them etc. I keep getting an error in my main function though when I go to create a list (List aList;) and the compiler says undefined reference to 'List::List()' I can't figure out why it won't let me create a list since I've included the header files.
/** @file ListAexcept.h */
#ifndef _LIST_H
#define _LIST_H
#include "listExceptions.h"
constint MAX_LIST = 20;
typedefint ListItemType;
/** @class List
* ADT list - Array-based implementation with exceptions */
class List
{
public:
List();
// destructor is supplied by compiler
/** @throw None. */
bool isEmpty() const;
/** @throw None. */
int getLength() const;
/** @throw ListIndexOutOfRangeException If index < 1 or index >
* getLength() + 1.
* @throw ListException If newItem cannot be placed in the list
* because the array is full. */
void insert(int index, const ListItemType& newItem)
throw(ListIndexOutOfRangeException, ListException);
/** @throw ListIndexOutOfRangeException If index < 1 or index >
* getLength(). */
void remove(int index)
throw(ListIndexOutOfRangeException);
/** @throw ListIndexOutOfRangeException If index < 1 or index >
* getLength(). */
void retrieve(int index, ListItemType& dataItem) constthrow(ListIndexOutOfRangeException);
List operator << (const List& vector) const;
List operator ++ ( int useless) const;
List operator ++ ( ) const;
//List operator / (const List& int num) const;
//List operator * (const List& int num) const;
List operator - (const List& rhs) const;
List operator + (const List& rhs) const;
private:
/** array of list items */
ListItemType items[MAX_LIST];
/** number of items in list */
int size;
int translate(int index) const;
}; // end List
// End of header file.
#endif
I just copy'pasted it into ideone ( http://ideone.com/QeqYe ), a couple of minor issues needed resolving, nothing related to the constructor.
List.cpp
- Missing class scope declarations for member functions, from line 85 down.
- Parameters for List::operator* & List::operator/(constList&int num) // ?? . I see you've commented these functions out in the header, you may wish to do so in the cpp file too.
- List::operator<< declaration in the header does not match the definition, missing the const qualifier.
A couple of the overloaded operators are questionable, I recommend you thoroughly read through:-
http://stackoverflow.com/questions/4421706/operator-overloading