返回 NULL 值
Framebufferd3d11.h 的片段
namespace dx11 {
...
class FramebufferManager : public FramebufferManagerBase
{
public:
...
private:
...
static struct Efb
{
...
std::unique_ptr<D3DTexture2D> resolved_color_tex;
std::unique_ptr<D3DTexture2D> resolved_depth_tex;
} m_efb;
};
} //namespace
Framebufferd3d11.cpp 的片段
namespace DX11
{
...
FramebufferManager::Efb FramebufferManager::m_efb;
...
FramebufferManager::FramebufferManager()
{
...
m_efb.resolved_color_tex = NULL;
m_efb.resolved_depth_tex = NULL;
}
} //namespace
如果我使用 icc 进行编译,则会遇到 NULL 赋值问题,因为 NULL 被定义为 0。我该如何解决这样的问题?
Snippets of framebufferd3d11.h
namespace dx11 {
...
class FramebufferManager : public FramebufferManagerBase
{
public:
...
private:
...
static struct Efb
{
...
std::unique_ptr<D3DTexture2D> resolved_color_tex;
std::unique_ptr<D3DTexture2D> resolved_depth_tex;
} m_efb;
};
} //namespace
Snippets of framebufferd3d11.cpp
namespace DX11
{
...
FramebufferManager::Efb FramebufferManager::m_efb;
...
FramebufferManager::FramebufferManager()
{
...
m_efb.resolved_color_tex = NULL;
m_efb.resolved_depth_tex = NULL;
}
} //namespace
If I compile with icc, I get a problem with NULL assign value, as NULL is defined as 0. How do I solve a problem like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码是正确的。以下所有内容都应该有效:
空指针常量(如
0
或NULL
)可隐式转换为nullptr_t
和unique_ptr 有一个采用
nullptr_t
的赋值运算符。如果您使用的 ICC 版本尚不支持nullptr
,这可以解释为什么NULL
的分配对您不起作用。使用
reset()
可能会有更好的运气:或者,因为
NULL
是默认参数:Your code is correct. All of the following should work:
A null pointer constant (like
0
orNULL
) is implicitly convertible tonullptr_t
andunique_ptr
has an assignment operator that takes anullptr_t
. If the version of ICC that you are using does not yet supportnullptr
, that could explain why the assignment ofNULL
doesn't work for you.You may have better luck using
reset()
:or, since
NULL
is the default argument:切勿在构造函数主体中初始化成员。如果它们具有重要的构造函数,则首先调用它,然后使用
operator=
重新初始化它们。而是使用基类和成员初始值设定项列表。就像:在你的情况下,事实证明:
resolved_color_tex()
或根本没有提到它,就会调用它)已经做了你想要的事情。Never initialize members in the body of the constructor. If they have non-trivial constructor, it is first called and than
operator=
is used to reinitialize them. Instead use the base and member initializer list. Like:In your case it turns out that:
resolved_color_tex()
or not mention it at all) already does what you want.