VS10中weak_ptr比较的问题

时间:2010-07-22 14:41:57

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

我无法获得'operator<'使用VS10编译weak_ptr。我错过了#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; 

    return (0); 
    } 

1 个答案:

答案 0 :(得分:1)

事实证明,头文件中没有未注释的'bool运算符&lt;(const weak_ptr&amp;,const weak_ptr&amp;)。与文档相反,这是不受支持的。