小编Sha*_* Li的帖子

为什么std :: move将rvalue引用作为参数?

根据cppreference.com,move有签名

template< class T >
typename std::remove_reference<T>::type&& move( T&& t ) noexcept;
Run Code Online (Sandbox Code Playgroud)

为什么它需要一个右值参考T&& t作为它的arugment?

当我尝试以下代码时

void foo(int&& bar) {
    cout << "baz" << endl;
}

int main(){
    int a;
    foo(a);
}
Run Code Online (Sandbox Code Playgroud)

我从编译器得到一个错误"rvalue引用不能绑定到左值"

到底是怎么回事?我很困惑.

c++ move rvalue-reference c++11 forwarding-reference

5
推荐指数
1
解决办法
752
查看次数

android SharedPreferences apply() 竞争条件

根据android developer reference,apply() 方法将

与将其首选项同步写入持久存储的 commit() 不同,apply() 立即将其更改提交到内存中的 SharedPreferences,但会启动对磁盘的异步提交,并且您不会收到任何失败通知。

很明显,apply() 是一个异步调用,这意味着在另一个线程中工作。但是我想知道 apply() 方法是否容易受到竞争条件的影响?

android android-sharedpreferences

5
推荐指数
0
解决办法
487
查看次数

如何防止系统在没有窗口的情况下关闭?

我有带有此源代码的Windows应用程序

#include <Windows.h>
#include <thread>
#include <chrono>

int WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR    lpCmdLine,
    int       cmdShow)
{
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch (Message)
    {
        case WM_QUERYENDSESSION:
            MessageBox(NULL, "Triggered?", "Message", 0);
            AbortSystemShutdown(NULL);
            return 0;

        default:
            return DefWindowProc(hWnd, Message, wParam, lParam);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我需要知道系统何时关闭并阻止它,或者至少向用户发送一条消息。

我的应用程序似乎没有收到该WM_QUERYENDSESSION消息。

我也尝试过使用,ShutdownBlockReasonCreate()但我没有HWND窗口。

我该怎么做?

c++ winapi shutdown

2
推荐指数
1
解决办法
1799
查看次数