How to clear/empty priority_queue of objects

Ok. I'm a beginner and missed that fact that I was missing the open and closed parentheses next to "pop". It's a method. Duh!!! Thanks for reading.

I would like to have a priority_queue of what I would, previously, have thought of as a struct. So, I created class called PqElement. This class has 2 members (an int and a double). I want the priority_queue to be ordered on the double in ascending order (smallest on top).

The error I am getting is on a small function/method in my class PriorityQueue.
Can someone help me figure this out and resolve it?

The error is:

Error C3867 'std::priority_queue<PqElement,std::vector<PqElement,std::allocator<PqElement>>::pop':non-standard syntax; use '&' to create a pointer to member

The PqElement class:
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
class PqElement {
public:
	//===================
	// Constructor
	//===================
	PqElement(int n = 0, double nv = 0.0) : pqN(n), pqNV(nv) {}

	//===================
	// Function: set_pqN
	// Set Node ID (index) in pqelement
	//===================
	void set_pqN(int n) {
		pqN = n;
	}

	//===================
	// Function: set_pqNV
	// Set Node Value in pqelement
	//===================
	void set_pqNV(double nv) {
		pqNV = nv;
	}

	//===================
	// Function: get_pqN
	// Get Node ID (index) from pqelement
	//===================
	int get_pqN() { return pqN; }

	//===================
	// Function: get_pqNV
	// Get Node Value from pqelement
	//===================
	double get_pqNV() { return pqNV; }

private:
	int pqN;             // Node ID which can be used as the index into a number of vectors
	double pqNV;         // Node Value (current distance to the node)

}; // end Class PqElement 


The ComparePQE class:
1
2
3
4
5
6
7
8
9
10
class ComparePQE {  
public:
	// Operator override
	bool operator()(PqElement& lhs, PqElement& rhs) {
		double lnv = lhs.get_pqNV();
		double rnv = rhs.get_pqNV();
	
		return lnv > rnv;
	}
};  // end Class ComparePQE 


Here is the declaration of the priority_queue in my PriorityQueue class:
1
2
private:
       priority_queue<PqElement, vector<PqElement>, ComparePQE> pq;



THE ERROR ...
The code in PriorityQueue class that is flagged as having the error error:
1
2
3
4
5
	void clrPQ() {
		while (!pq.empty()) {
			pq.pop;           // <<<<< THIS IS THE LINE THAT GETS THE ERROR
		}
	}

Last edited on
Is pop a function? Then call it like you would call another function.

empty is a function --> it's called like pq.empty()
pop is a function --> it's called like pq.pop()
Topic archived. No new replies allowed.