Caladbolgll
Caladbolgll

Reputation: 87

Creating std::priority queue of std::pair of customized class

(Previously referred) STL Priority Queue on custom class

It may sound unnecessarily complex, but I'm trying to create a std::pair of a customized class and a 2D array of enum availability type. Here is a declaration of the queue:

std::priority_queue < std::pair<Panel_string, availability**>*, std::vector<std::pair<Panel_string, availability**>*>, compareString > queue_string;

and here is a comparing function for the queue (each pair will be ordered according to its weight):

struct compareString {
bool operator() (const std::pair<Panel_string, availability**>* left, const std::pair<Panel_string, availability**>* right) const {
    return left->first->weight > right->first->weight;
}
};

I referred to the link above for the syntax of this.

However, I cannot compile it because there are only two errors detected in the compareString struct. In Visual Studio, two red line shows up in "left" and "right" (line 3 of the struct compareString), both alerting:

IntelliSense: expression must have pointer type.

If you're the expert I'm looking for, please help me ):

Upvotes: 1

Views: 441

Answers (1)

juanchopanza
juanchopanza

Reputation: 227390

Your pair's first element isn't a pointer, so don't use ->.

return left->first.weight > right->first.weight;

-> is for use in expressions that must have pointer type (or evaluate to instances of things that overload operator->.)

Upvotes: 2

Related Questions