阅读背景:

是否绑定到本地引用的对象会自动销毁?

来源:互联网 

Consider the following code.

请考虑以下代码。

struct MyImage
{
    MyImage(const int handle);
    MyImage(const CString& filePath);
    virtual ~MyImage();

    void Process();
    void SaveAs(const CString& filePath);

    // No copying!
    MyImage(const MyImage& other) = delete;
    MyImage& operator=(const MyImage& other) = delete;
}

void ProcessImageFile(const CString& inFilePath, const CString& outFilePath)
{
    MyImage& image = MyImage(-1); // initialized with invalid handle

    if (DecryptionRequired())
    {
        const CString tempFilePath = ::GetTempFileName();
        Decrypt(inFilePath, tempFilePath);
        image = MyImage(tempFilePath);
        _tremove(tempFilePath);
    }
    else
    {
        image = MyImage(inFilePath);
    }

    image.Process();
    image.SaveAs(outFilePath);
}
struc



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: