Overloaded constructor

On my overloaded constructor for Node, I'm getting an error saying that 'No instance of overloaded function Node::Node matches the specified type'. What is the deal?

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
#pragma once
#include <string>

struct Node
{
	Node *previous;
	Node *next;
	int priority_rating;
	string name;

	Node ();
	Node (string name, int priority_rating, Node *previous = NULL, Node *next = NULL);
};

class PriorityQueue
{
protected:
	Node *head;

public:
	PriorityQueue();
	PriorityQueue(string name, int priority_rating);
	void add_to_list (string name, int priority_rating);
	void getHead ();
};

// beginning of Node Implementation
Node::Node()
{
	previous = NULL;
	next = NULL;
	priority_rating = 0;
	name = "";
}
Node::Node (string _name, int _priority_rating, Node *_previous = NULL, Node *_next = NULL)
{
	name = _name;
	priority_rating = _priority_rating;
	previous = _previous;
	next = _next;
}
The faulty line of code doesn't seem to be in what you show. The error is most likely in your calls to new Node(....). Show your constructions of new nodes.
I haven't actually implemented any of it yet. I haven't written a main(), I'm still just working on coding the header file
It could then be because your parameter names of Node::Node() have an underscore in the definition, but not in the declaration. See if that fixes it.
That shouldn't matter.

Only thing I can see is that it should be std::string instead of string. But that should be giving you different errors.

What line of code is the error occuring on?
line 35. Also, what do you mean by the std::string; is that a #include?
line 35.


Only thing I see that's obviously wrong is that you are redefining the default parameters. You should only do that in the prototype. Get rid of the default params on line 35.

Also, what do you mean by the std::string; is that a #include?


No, <string> is the #include, but the string class is actually inside the std namespace. So unless you have using namespace std;, you need to fully qualify the name as std::string.

For example line 9 should be std::string name; instead of just string name;

Likewise, you'd need to change all occurances of string the same way. Alternatively you can put using namespace std; or using std::string; under your includes.


After making those two changes, the code compiles fine here.
Topic archived. No new replies allowed.