表达式必须是左值
问题描述:
有很多这样的问题,但通过他们并没有解决我的问题。表达式必须是左值
作为第三参数的PSSetShaderResources
想要ID3DShaderResourceView* const*
。
,所以我不能让这样的(因为我得到了左值误差):
// std::unique_ptr<Texture> mTexture;
// ID3D11ShaderResourceView* Texture::getTexture() const {
// return mTexture;
// }
deviceContext->PSSetShaderResources(0U, 1U, &mTexture->getTexture());
这就是为什么我找到了解决办法,使这样说:
auto tex = mTexture->getTexture();
deviceContext->PSSetShaderResources(0U, 1U, &tex);
然而,我想摆脱auto tex = ...
线。 像第一种情况一样,是否可以改变getTexture()方法(或者不改变它)来编写?
答
好吧,我已经改变了getTexture()
方法来解决它:
ID3D11ShaderResourceView* const* Texture::getTexture() const {
return &mTexture.p; // this is a CComPtr<ID3DShaderResourceView> mTexture;
}
用名称'PSSetShaderResources'我猜的功能要设置* *指针,这是你要的原因来看将指针传递给指针。当你用'getTexture'调用它时,你会给它一个指向*临时*的指针。 –
@JoachimPileborg但是如果我使用'auto tex = ...'它也是一个临时(当我们离开tex所在的方法时它将被删除)并且它仍然有效。 – tobi
@tobi tex对你来说是暂时的,但编译器并不知道,它只是一个普通的变量,因此对于编译器来说不是临时的。 – bennofs