Posts

Showing posts with the label Reference

C++ Difference Between Std::ref(T) And T&?

Answer : Well ref constructs an object of the appropriate reference_wrapper type to hold a reference to an object. Which means when you apply: auto r = ref(x); This returns a reference_wrapper and not a direct reference to x (ie T& ). This reference_wrapper (ie r ) instead holds T& . A reference_wrapper is very useful when you want to emulate a reference of an object which can be copied (it is both copy-constructible and copy-assignable ). In C++, once you create a reference (say y ) to an object (say x ), then y and x share the same base address . Furthermore, y cannot refer to any other object. Also you cannot create an array of references ie code like this will throw an error: #include <iostream> using namespace std; int main() { int x=5, y=7, z=8; int& arr[] {x,y,z}; // error: declaration of 'arr' as array of references return 0; } However this is legal: #include <iostream> #include <functional> // ...

Could Not Load File Or Assembly 'System.Buffers, Version=4.0.2.0...'

Answer : Could not load file or assembly 'System.Buffers, Version=4.0.2.0…' Solution 1) use CMD(run as Administrator ) and type cd xxxx(xxxx\packages\System.Buffers.4.5.1\lib\netstandard2.0)) run gacutil /i System.Buffers.dll Then , when you finish it, please run update-package -reinstall under package manager console to reinstall the package. 2) you can try to change Version=4.0.2.0 to Version=4.0.3.0 in csproj file. Besides , there is a similar issue you can refer to.