c++ - 无法在 VS10 中订购 weak_ptr

标签 c++ c++11 visual-studio-2010 smart-pointers tr1

我无法使用 VS10 为 weak_ptr 编译“operator <”。我是否缺少#include 或#using?

即使是文档中的代码示例也不适合我。 http://msdn.microsoft.com/en-us/library/bb982759.aspx

// temp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

// std_tr1__memory__operator_lt.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>

int main()
{
    std::shared_ptr<int> sp0(new int(0));
    std::shared_ptr<int> sp1(new int(0));

    std::cout << "sp0 < sp0 == " << std::boolalpha
        << (sp0 < sp0) << std::endl;
    std::cout << "sp0 < sp1 == " << std::boolalpha
        << (sp0 < sp1) << std::endl;
    std::cout << "sp1 < sp0 == " << std::boolalpha
        << (sp1 < sp0) << std::endl;
    std::cout << std::endl;

    std::weak_ptr<int> wp0(sp0);
    std::weak_ptr<int> wp1(sp1);

    std::cout << "wp0 < wp0 == " << std::boolalpha
        << (wp0 < wp0) << std::endl;
    std::cout << "wp0 < wp1 == " << std::boolalpha
        << (wp0 < wp1) << std::endl;
    std::cout << "wp1 < wp0 == " << std::boolalpha
        << (wp1 < wp0) << std::endl;
}

最佳答案

原来是头文件中没有未注释的'bool operator<(const weak_ptr&, const weak_ptr&)。因此,与文档相反,这是不受支持的。

关于c++ - 无法在 VS10 中订购 weak_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3310065/

相关文章:

c++ - 使用 O(n) 时间和 O(1) 空间从数组中查找缺失的数字

c++ - 替代字符串::npos

c++ - std::string,string val 和 string val 之间的区别 = ""

c++ - 自动推断方法的返回类型

c# - 使用 Properties.Settings 进行应用程序设置

c# - 将 C++ dll 导入 Windows Phone 项目

c++ - 为什么有些 STL 算法提供额外的 '_if' 函数而不是重载?

c++ - 如何从 std::list 中获取特定元素?

c++ - 数据库连接对象的名称游标的历史记录是什么?

c++ - 结构原型(prototype)