reference

In Rust, what exactly are mutable and immutable borrows?

久未见 提交于 2020-01-24 13:53:06
问题 I'm stuck with the Rust concepts of borrowing and mutable : #[derive(Debug)] struct Rectangle { height: u32, width: u32, } fn mut_area(rect_mut: &mut Rectangle) -> u32 { rect_mut.width /= 2; rect_mut.height * rect_mut.width } fn mut_string(s: &mut String) -> &str { s.push_str("!"); let len = s.len(); &s[0..len / 2] } fn main() { let mut rect = Rectangle { height: 50, width: 40, }; println!("original rect: {:?}", rect); let a = mut_area(&mut rect); println!("area of rect: {}", a); println!(

In Rust, what exactly are mutable and immutable borrows?

烈酒焚心 提交于 2020-01-24 13:52:00
问题 I'm stuck with the Rust concepts of borrowing and mutable : #[derive(Debug)] struct Rectangle { height: u32, width: u32, } fn mut_area(rect_mut: &mut Rectangle) -> u32 { rect_mut.width /= 2; rect_mut.height * rect_mut.width } fn mut_string(s: &mut String) -> &str { s.push_str("!"); let len = s.len(); &s[0..len / 2] } fn main() { let mut rect = Rectangle { height: 50, width: 40, }; println!("original rect: {:?}", rect); let a = mut_area(&mut rect); println!("area of rect: {}", a); println!(

Is there a way to convert a list of lvalues and rvalues to a tuple with reference types and full types respectively?

北城以北 提交于 2020-01-24 12:18:54
问题 So given the following 2 functions: int rvalue(); int& lvalue(); The following would be valid: std::tuple<int&, int> x = appropriate_fn(lvalue(), rvalue()); I was thinking something like it like this: template <typename T, typename...Ts> auto make_comparible(T const& arg, Ts&&...args) { return std::make_tuple(T(arg), make_comparible(args...)); } template <typename T, typename...Ts> auto make_comparible(T& arg, Ts&&...args) { return std::make_tuple<T&>(arg, make_comparible(args...)); }

Initializing reference member variable with literal

走远了吗. 提交于 2020-01-24 08:41:25
问题 In the following code , I am initializing a reference variable with a literal. class ABC { public: const int& a; ABC():a(43) { } void newfoo() { printf("NEWFOO %d",a); } }; int main() { ABC obj; obj.newfoo(); } The output of this program is NEWFOO 32767 which seems illogical when I know that the following code works just fine. int main() { const int& b=3; printf("%d",b); } What is happening here ? If compiler declares some temp variable during initializing of the reference variable , then isn

How to create a reference to a value-field

空扰寡人 提交于 2020-01-23 02:54:30
问题 Is there a way in C# to create a field which is a reference to another field which is a value type? class myClass { bool b1; public void method1(ref bool b) { b1 = b; } } I want b1 to reference the value of b, just as b references the value of the original argument, so that changes to b1 will affect the original argument. EDIT: What I’m trying to achieve is a myCheckBox class which automatically updates a field. See: How do I change a value argument from within an event handler? 回答1: Well...

Update DLL reference

雨燕双飞 提交于 2020-01-22 13:08:06
问题 I wanted to update some DLLs used in my .NET project to the latest version and I've noticed that, if I replace the DLLs on the file system with their new versions, VS 2012 updates the DLL version number in the Properties window. Is this some new feature of VS 2012? I don't remember seeing it in VS 2010 (I expected it would need more manual handling). Is this working right, or should I remove and re-add the DLLs manually from the references, just to be sure? Anyway, my project compiles and

reference to generic type in XML code comment [duplicate]

北城余情 提交于 2020-01-22 04:57:07
问题 This question already has answers here : How to reference generic classes and methods in xml documentation (7 answers) Closed 6 years ago . As I know, in a XML comment for a C# type/method, it is possible to reference a generic type in a tag like so: ///<see cref="name.space.typename<T&rt;(paramtype)"> But I think, there was another syntax, which is less clumsy? Something, to get rid of those html entities '<'? I cannot find it right now. Can somebody help? 回答1: Here's a good article on

Dependencies and references - What exactly should I reference?

做~自己de王妃 提交于 2020-01-21 07:15:38
问题 I am wondering what to include when building my project. I have a library I need to reference for my project to build but that library has 10 dependencies itself. Should I reference those dependencies as well or should I copy them to the output directory using a post build event? What is the best practice? I find it confusing to include all those dependencies as the project compiles fine without them - are they then called runtime dependencies? My references become cluttered with dependencies

How to identify failed casts using dynamic_cast operator?

我们两清 提交于 2020-01-20 03:59:45
问题 Scott Meyer in his book Effective C++ says dynamic_cast is used to perform safe casts down or across an inheritance hierarchy. That is, you use dynamic_cast to cast pointers or references to base class objects into pointers or references to derived or sibling base class objects in such a way that you can determine whether the casts succeeded. Failed casts are indicated by a null pointer (when casting pointers) or an exception (when casting references). I would like to get two code snippet

Some x86 ASM Reference/Tutorials? [closed]

喜你入骨 提交于 2020-01-19 19:03:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm trying to find some references in regards to x86 Assembly languages. Tutorials/Examples to help my understanding. -Thanks 回答1: Programming from the Ground Up (free book, highly recommended) x86 Assembly (wikibooks.org) Essential Resources for x86 Programmers 回答2: I recommend Roby's PC Assembly Tutorial