2010-07-22 12 views
1

Je ne peux pas obtenir 'opérateur <' pour compiler un weak_ptr en utilisant VS10. Ai-je manqué un #include ou #using?Problème avec la comparaison weak_ptr dans VS10

Même l'exemple de code dans la documentation ne fonctionne pas pour moi. 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); 
    } 

Répondre

1

Il se trouve qu'il n'y a pas décommentée « opérateur bool < (const weak_ptr &, const weak_ptr &) dans le fichier d'en-tête. Donc contratry à la documentation, ceci n'est pas supporté.