简体   繁体   English

为什么 ComPtr 的函数返回与 & 不同的值?

[英]Why does function of ComPtr return a different value then &?

Why &(ComPtr.Get()) != ComPtr.GetAddressOf()?为什么 &(ComPtr.Get()) != ComPtr.GetAddressOf()?

I tryed to pass ID3D11ShaderResourcesView* to function and convert it to ** to use in CreateShaderResourceView, but it didnt work correct.我尝试将 ID3D11ShaderResourcesView* 传递给函数并将其转换为 ** 以在 CreateShaderResourceView 中使用,但它无法正常工作。

I realized, that the problem in 3 argument.我意识到,问题在 3 个参数中。

You are taking the address of the pointer that ComPtr.Get() returns.您正在获取ComPtr.Get()返回的指针的地址。 That's entirely different to the pointer to the object.这与指向对象的指针完全不同。

ComPtr.Get() returns the held pointer by value , so &(ComPtr.Get()) is taking the address of a copy of the held pointer. ComPtr.Get()按 value返回持有的指针,因此&(ComPtr.Get())正在获取持有指针副本的地址。

ComPtr.GetAddressOf() returns the address of the held pointer itself, not a copy of it. ComPtr.GetAddressOf()返回持有的指针本身的地址,而不是它的副本。

Had ComPtr.Get() returned the held pointer by reference instead then &(ComPtr.Get()) would take the address of the original pointer, not a copy.如果ComPtr.Get()通过引用返回持有的指针那么&(ComPtr.Get())将采用原始指针的地址,而不是副本。 But it does not return a reference.但它不返回引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM