没有:
如何使用FormatMessage()获取错误文本HRESULT?
HRESULT hresult = application.CreateInstance("Excel.Application");
if (FAILED(hresult))
{
// what should i put here to obtain a human-readable
// description of the error?
exit (hresult);
}
Run Code Online (Sandbox Code Playgroud) 我偶然发现了我正在使用的共享指针的意外行为.
共享指针实现引用计数和分离(例如,复制),如果需要,包含非const使用的实例.
为实现此目的,对于每个getter函数,智能指针都有一个const和一个non-const版本,例如:operator T *()和operator T const *() const.
问题:比较指针值nullptr导致分离.
预期:我认为比较运算符总是会调用const版本.
简化示例:(
此实现没有引用计数,但仍显示问题)
#include <iostream>
template<typename T>
class SharedPointer
{
public:
inline operator T *() { std::cout << "Detached"; return d; }
inline operator const T *() const { std::cout << "Not detached"; return d; }
inline T *data() { std::cout << "Detached"; return d; }
inline const T *data() const { std::cout << "Not detached"; …Run Code Online (Sandbox Code Playgroud)