开发者

Cannot order weak_ptr's in in VS10

开发者 https://www.devze.com 2023-01-08 04:51 出处:网络
I can not get \'operator <\' to compile for a weak_ptr using VS10. Am I missing an #include or #using?

I can not get 'operator <' to compile for a weak_ptr using VS10. Am I missing an #include or #using?

Even the the code sample in the documentation does not work for me. 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:开发者_StackOverflow中文版: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;
}


It turns out that there is no uncommented 'bool operator<(const weak_ptr&, const weak_ptr&) in the header file. So contratry to the documentation, this is unsupported.

0

精彩评论

暂无评论...
验证码 换一张
取 消