小编iss*_*sac的帖子

为什么在我的程序中调用了两次 operator()?

#include <unordered_set>
#include <stdio.h>

int hcount=0;

struct A{
    int i=0;

    A(){}
    A(const A&a) :i(a.i){}

    A(int const & i):i(i) {        
        printf("A ctor i=%d\n", i);
    }

    A&operator=(A &&a){
        this->i= a.i;
        return (*this);
    }
    bool operator==(A const &rhs) const {
        printf("A optor== i=%d\n", this->i);
        return rhs.i == this->i;
    }
};

namespace std{
    template<>
    struct hash<A> { 
        hash() {            
            hcount=0;
        }
        hash(int t) {
            hcount=t;
        }
        std::size_t operator()(A const &a) const {
            ++hcount;
            printf("hash: hcount=%d a.i=%d\n", hcount, a.i);
            return a.i;
        };
    };
}

int …
Run Code Online (Sandbox Code Playgroud)

c++ std

3
推荐指数
1
解决办法
89
查看次数

C++14 中是否去掉了 nanosleep() 的功能?

我尝试nanosleep()使用 C++14编译以下调用代码,但失败并出现错误:

'nanosleep' 未在此范围内声明
     nanosleep(&ts, NULL);
'nanosleep' was not declared in this scope
     nanosleep(&ts, NULL);

-DNDEBUG -O3 -DNDEBUG -o -c nanosleep-test.cpp -std=c++14 -fPIC -Wall -Wpedantic -Werror. 删除-std=c++14,我编译了它。那么说 C++14 删除了nanosleep()是否正确?

c++ c++14

0
推荐指数
1
解决办法
224
查看次数

标签 统计

c++ ×2

c++14 ×1

std ×1