【发布时间】:2020-12-15 23:30:13
【问题描述】:
我使用 VS 2012,它在这个 IDE 中给出了错误,在 2017 和 2019 上运行良好 它返回
1>consoleapplication2.cpp(41): error C2039: 'priority_queue' : is not a member of 'std'
和
error C2065: 'priority_queue' : undeclared identifier
这可能是什么原因?我可以使用一些#ifdef 来摆脱这个吗?我需要让它在 Visual Studio 2012 上工作,这就是我尝试的原因。我使用 C++,我也使用 realted 库。我只是注释掉以确保有什么不同。
// program in c++ to use priority_queue with class
#include <queue>
#include <iostream>
#include <vector>
#include "stdafx.h"
using namespace std;
#define ROW 5
#define COL 2
class Person {
public:
int age;
float height;
// this is used to initialize the variables of the class
Person(int age, float height)
: age(age), height(height)
{
}
};
// we are doing operator overloading through this
/*bool operator<(const Person& p1, const Person& p2)
{
// this will return true when second person
// has greater height. Suppose we have p1.height=5
// and p2.height=5.5 then the object which
// have max height will be at the top(or
// max priority)
return p1.height < p2.height;
} */
int main()
{
std::priority_queue<Person>;
float arr[ROW][COL] = { { 30, 5.5 }, { 25, 5 }, { 20, 6 }, { 33, 6.1 }, { 23, 5.6 } };
/* for (int i = 0; i < ROW; ++i) {
Q.push(Person(arr[i][0], arr[i][1]));
// insert an object in priority_queue by using
// the Person class constructor
}
while (!Q.empty()) {
Person p = Q.top();
Q.pop();
cout << p.age << " " << p.height << "\n";
} */
return 0;
}
【问题讨论】:
-
std::priority_queue<Person>;究竟应该做什么?这是一个类型,但它没有被用来声明任何东西。
标签: c++ visual-studio-2012 priority-queue