I am new to c++ and am really struggling with getting something simple working. When I use g++ I get one of the two type of errors shown above. I have looked around the forums and have gathered that it is a common question but when I fix with one answer I get the other error when using g++. I am interested in understanding this better.
#ifndef ORDEREDLIST_H_
#define ORDEREDLIST_H_
#include <iostream>
using namespace std;
class Node
{
public:
double item; // data item
Node *next; // pointer to next node
};
class OrderedList
{
// friend operator functions
friend ostream &operator<<(ostream &, const OrderedList &);
friend istream &operator>>(istream &, OrderedList &);
public:
// constructors
OrderedList():_head(NULL),_size(0) {};
OrderedList(const OrderedList &); // copy constructor
// destructor
~OrderedList();
// operator functions
OrderedList operator+(OrderedList&); // merges two OrderedLists
double operator[](int) const; // subscript operator returns rvalue
const OrderedList &operator=(const OrderedList &); // assignment
void insert(double); // inserts an item
bool remove(int); // remove i th item
void pop(); // pop the first item
void tester();
private:
Node *_head;
int _size;
};
#endif /* ORDEREDLIST_H_ */
The class functions are here:(NB I have only included a part of the code)
#include <iostream>
#include "OrderedList.h"
using namespace std;
OrderedList::OrderedList():_head(NULL),_size(0) {};
//OrderedList::OrderedList(const OrderedList &); // copy constructor
OrderedList::~OrderedList(){
//nothing
};
void OrderedList::pop()
{
//nothing yet
}
And then the simple test call to the pop function which currently does nothing doesn't work. I am just trying to get the code below to recognise the pop() function so that I can continue to build my program incrementally.
#include <iostream>
#include "OrderedList.h"
using namespace std;
int main()
{
OrderedList* List_A = new OrderedList;
cout<<"Hello"<<endl;
List_A->pop();
return 0;
};
The exact error I get is:
In function main':
ass2q1.cpp:(.text+0x46): undefined reference to
OrderedList::pop()'
collect2: error: ld returned 1 exit status