2010-07-22 57 views
1

我無法使用VS10爲'weak_ptr'編譯'operator <'。我是否錯過#include或#using?VS10中的weak_ptr比較存在問題

即使在文檔中的代碼示例不適用於我。 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

事實證明,沒有未註釋「布爾運算符<在頭文件(常量的weak_ptr &,常量的weak_ptr &)。因此,與文檔相比,這是不受支持的。