C++ error

NewcastlePort.cpp: In function ‘int main(int, const char**)’:
NewcastlePort.cpp:30: error: no matching function for call to ‘SENG1120_ASS2::Queue<SENG1120_ASS2::Ship>::push(SENG1120_ASS2::Ship**)’
Queue.template:63: note: candidates are: void SENG1120_ASS2::Queue<Item>::push(const Item&) [with Item = SENG1120_ASS2::Ship]
make: *** [NewcastlePort.o] Error 1

I am getting the following error when trying to compile my program, i have been trying to fix it and have no idea how to, anyone shed some light and help fix this problem, would be much appreciated.

Here are the files below:
NewcastlePort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <fstream>
#include <string>
#include "Ship.h"
#include "Node.h"
#include "Queue.h"
#include "LinkedList.h"
using namespace std;
using namespace SENG1120_ASS2;

int main(int argc, const char * argv[])
{
	Queue<Ship> q;
	
		int ships;
	int count = 1;
	cout << "Please enter the number of ships: " << endl;
	cin >> ships;
	
	while (count <= ships)
	{
		Ship* s;
		q.push(&s);
		count++;
	}



}



Queue.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "LinkedList.h"
#include "Node.h"
#include "Queue.h"
#include <cassert>
#include <cstdlib>
using namespace std;

namespace SENG1120_ASS2{
	
	template <class Item>
	Queue<Item>::Queue()
	{
		count = 0;
		front_ptr = NULL;
	}
	
	template <class Item>
	Queue<Item>::Queue(const Queue<Item>& source)
	{
		count = source.count;
		shipsL->list_copy(source, front_ptr, front_ptr, rear_ptr); //Linked List
	}
	
	/*template <class Item>
	Queue<Item>::~Queue()
	{
		shipsL->list_clear(front_ptr); //Linked List
	}*/
	
	template <class Item>
	void Queue<Item>::operator =(const Queue<Item>& source)
	{
		if (this == &source)
			return;
		shipsL->list_clear(front_ptr);
		shipsL->list_copy(source, front_ptr, front_ptr, rear_ptr);
		count = source.count;
	}
	
	template <class Item>
	Item Queue<Item>::front() const
	{
		assert(!empty());
		return front_ptr->data();
	}
	
	template <class Item>
	void Queue<Item>::pop()
	{
		assert(!empty());
		shipsL->list_head_remove(front_ptr);
		--count;
	}
	
	template <class Item>
	void Queue<Item>::push(const Item& entry)
	{
		if (empty())
		{
			shipsL->list_head_insert(front_ptr, entry);
			rear_ptr = front_ptr;
		}
		else
		{
			shipsL->list_insert(rear_ptr, entry);
			rear_ptr = rear_ptr->link();
		}
		++count;
	}
	
	
}
Why are you trying to push() a the address of a Ship* into the Queue? You declared it to hold Ships, not Ship**s.
Right, so is this fixed by just declaring ships as:
Ship s;
Now i get this error:
undefined symbols for architecture x86_64:
"SENG1120_ASS2::Queue<SENG1120_ASS2::Ship>::~Queue()", referenced from:
_main in NewcastlePort.o
ld: symbol(s) not found for architecture x86_64
Maybe you should un-comment the definition of ~Queue().
Still got the same error
closed account (Dy7SLyTq)
will you post the header?
Is this "Queue.template" being included like a source file in your project? That would be wrong.

Queue.template should not #include "Queue.h" . It should be included by Queue.h after the class definition.
It was included in the template but i removed, still getting the exact same error?
Thanks for the input guys

EDIT: It now compiles thank you so much, but now I'm getting a segmentation fault,

has to do with the line:
q.push(s);
Last edited on
You haven't initialized Ship *s in line 22 of NewcastlePort.cpp, maybe you meant to do this:
1
2
3
4
Ship* s = new Ship;
q.push(s);
delete s;
count++;
Last edited on
main now looks like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(int argc, const char * argv[])
{
	Queue<Ship> q;
	
		int ships;
	int count = 1;
	cout << "Please enter the number of ships: " << endl;
	cin >> ships;
	
	while (count <= ships)
	{
		Ship s;
		q.push(s);
		count++;
		cout << "MEAL" << endl;
	}



}
Topic archived. No new replies allowed.