Mam problem z konstruktorem kolejki, wszystko jest ok dopóki nie tworzę jej w mainie, wtedy wyskakuje mi coś takiego:
Miałem podobny problem kiedy pisałem stos, ale nagle zniknął, dodam że pracuję na Linuxie i jestem ciekaw czy to może być wina systemu.
#include <iostream>
#include "Queue_implementation.h"
using namespace std;
int main()
{
Queue <int> Test;
return 0;
}
#ifndef QUEUE_IMPLEMENTATION_H_INCLUDED
#define QUEUE_IMPLEMENTATION_H_INCLUDED
#include <stdexcept>
template <class Type>
class Queue
{
struct node
{
Type data;
node * next;
node(Type newData)
{
data = newData;
next = NULL;
}
};
node head, rear;
public:
Queue();
bool isEmpty() const;
void push(Type);
Type get();
Type front();
~Queue();
};
template <class Type>
Queue<Type>::Queue()
{
head = rear = NULL;
}
template <class Type>
bool Queue<Type>::isEmpty()const
{
return head == NULL;
}
template <class Type>
void Queue<Type>::push(Type newData)
{
node temp_rear = rear;
rear = new node(newData);
if (head == NULL)
head = rear;
else
temp_rear->next = temp_rear;
}
template <class Type>
Type Queue<Type>::get()
{
if(head == NULL )
throw std::out_of_range("Queue is empty!");
Type data = rear->data;
node newHead = head->next;
delete head;
head = newHead;
return data;
}
template <class Type>
Type Queue<Type>::front()
{
if(head == NULL)
throw std::out_of_range("Kolejka pusta!");
return head->data;
}
template <class Type>
Queue<Type>::~Queue()
{
while(!isEmpty())
{
get();
}
}
#endif // QUEUE_IMPLEMENTATION_H_INCLUDED