【问题标题】:Priority queue is not definede VS 2012VS 2012 未定义优先级队列
【发布时间】: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; 
} 

【问题讨论】:

标签: c++ visual-studio-2012 priority-queue


【解决方案1】:

我的猜测是 Visual Studio 2012 不支持std::priority_queue。在线查找文档发现std::priority_queue在官方C++标准C++98和C++11中略有不同。但是,我无法找到有关标准 Visual Studio 2012 支持哪些部分的详细信息。

希望 StackOverflow 上的其他人能够提供此信息。

除此之外,我建议通过 Visual Studio 2012 头文件搜索 priority_queue。如果它不在头文件中,则不支持。而且您将不得不使用其他一些优先级队列解决方案。

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 2012-03-03
    • 2017-04-11
    • 1970-01-01
    • 2011-12-20
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多