Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 表达式必须是左值_C++ - Fatal编程技术网

C++ 表达式必须是左值

C++ 表达式必须是左值,c++,C++,有很多这样的问题,但在我的案例中,通过这些问题并不能解决问题 PSSetShaderResources作为第三个参数需要ID3DShaderResourceView*const* 所以我不能这样做(因为我得到了左值错误): 但是,我想去掉auto-tex=…行是否有可能将getTexture()方法更改(或不更改)为与第一种情况相同的写入方式?好的,我通过将getTexture()方法更改为: ID3D11ShaderResourceView* const* Texture::getTextur

有很多这样的问题,但在我的案例中,通过这些问题并不能解决问题

PSSetShaderResources
作为第三个参数需要
ID3DShaderResourceView*const*

所以我不能这样做(因为我得到了左值错误):


但是,我想去掉
auto-tex=…
是否有可能将getTexture()方法更改(或不更改)为与第一种情况相同的写入方式?

好的,我通过将
getTexture()方法更改为:

ID3D11ShaderResourceView* const* Texture::getTexture() const {
    return &mTexture.p; // this is a CComPtr<ID3DShaderResourceView> mTexture;
}
ID3D11ShaderResourceView*常量*纹理::getTexture()常量{
return&mTexture.p;//这是一个CComPtr mTexture;
}

根据名称判断
PSSetShaderResources
我猜函数想要设置指针,这就是您必须将指针传递给指针的原因。当你用
getTexture
调用它时,你是在给它一个指向临时对象的指针。@JoachimPileborg但是如果我使用
auto-tex=…
它也是临时对象(当我们离开tex所在的方法时,它将被删除),它仍然有效。@tobi-tex对你来说是临时对象,但编译器不知道,它只是一个普通变量,因此不是编译器的临时变量。
auto tex = mTexture->getTexture();
deviceContext->PSSetShaderResources( 0U, 1U, &tex );
ID3D11ShaderResourceView* const* Texture::getTexture() const {
    return &mTexture.p; // this is a CComPtr<ID3DShaderResourceView> mTexture;
}