Hello, I was trying to make a simple queue by using classes.
Problem is, I can't seem to get it working.
When I compile it into a .o file, it all works, but when I compile the .o file, I get this error:
classQueue.o: In function `Queue::enqueue(int)':
classQueue.cpp:(.text+0x23): undefined reference to `Node::Node()'
collect2: ld returned 1 exit status
This is my .cpp file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include "classQueue.h"
void Queue::enqueue(int value)
{
Node *newNode = new Node;
newNode->value = value;
if(Queue::head == NULL)
{
Queue::head = newNode;
Queue::tail = newNode;
}
}
int main()
{
Queue *Q;
Q->head = NULL;
Q->enqueue(2);
}
|
And this is my custom header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef INC_CLASSQUEUE_H
#define INC_CLASSQUEUE_H
class Node
{
public:
Node();
Node *next;
int value;
~Node();
};
class Queue
{
public:
Queue();
void enqueue(int);
Node *head;
Node *tail;
~Queue();
};
#endif //INC_CLASSQUEUE_H
|
Help would be very much appreciated,
I need a fast response though, I have an exam on this tomorrow,
And I'm having some trouble with classes.