reference

Why does cloning my custom type result in &T instead of T?

时光怂恿深爱的人放手 提交于 2020-01-19 14:11:13
问题 use generic_array::*; // 0.12.3 use num::{Float, Zero}; // 0.2.0 #[derive(Clone, Debug)] struct Vector<T, N: ArrayLength<T>> { data: GenericArray<T, N>, } impl<T, N: ArrayLength<T>> Vector<T, N> where T: Float + Zero, { fn dot(&self, other: Self) -> T { self.data .iter() .zip(other.data.iter()) .fold(T::zero(), |acc, x| acc + *x.0 * *x.1) } fn length_sq(&self) -> T { self.dot(self.clone()) } } error[E0308]: mismatched types --> src/lib.rs:21:18 | 21 | self.dot(self.clone()) | ^^^^^^^^^^^^

undefined reference to function declared in *.h file

吃可爱长大的小学妹 提交于 2020-01-19 12:55:07
问题 I am a unskilled programmer and new to linux, I run into a problem when complining. I have two files 'ex_addinst.c' and 'lindo.h' in the same folder, I input command : g++ -c ex_addinst.c then, a object file ex_addinst.o is genetated with a warning: ex_addinst.c: In function ‘int main()’: ex_addinst.c:80: warning: deprecated conversion from string constant to ‘char*’ then I leak them with g++ -Wall -o ex_addinst ex_addinst.o and get the following info: ex_addinst.o: In function `main': ex

Why don't methods have reference equality?

最后都变了- 提交于 2020-01-18 04:43:14
问题 I had a bug where I was relying on methods being equal to each other when using is . It turns out that's not the case: >>> class What(object): def meth(self): pass >>> What.meth is What.meth False >>> inst = What() >>> inst.meth is inst.meth False Why is that the case? It works for regular functions: >>> def func(): pass >>> func is func True 回答1: Method objects are created each time you access them . Functions act as descriptors, returning a method object when their .__get__ method is called

Difference between pointer and reference as thread parameter

倾然丶 夕夏残阳落幕 提交于 2020-01-18 04:28:17
问题 This is the example: #include<iostream> #include<thread> using namespace std; void f1(double& ret) { ret=5.; } void f2(double* ret) { *ret=5.; } int main() { double ret=0.; thread t1(f1, ret); t1.join(); cout << "ret=" << ret << endl; thread t2(f2, &ret); t2.join(); cout << "ret=" << ret << endl; } And the output is: ret=0 ret=5 Compiled with gcc 4.5.2, with and without -O2 flag. Is this expected behavior? Is this program data race free? Thank you 回答1: The constructor of std::thread deduces

Reflect, generate, compile, execute, disassemble, decompile, reflect

安稳与你 提交于 2020-01-17 07:01:12
问题 Before heading back to business, I decided to take a few days off for recreational coding. A few 30-hour days without fresh air? Sounds fantastic, for a change. I've struggled with managed code generation over time and always wondered if there is a circular relationship between C# code, reflection and codedom. Never got around to exploring it sadly. So the goal is to create useless and annoyingly complex classes with nested generics, constraints, anonymous methods, delegates, nested complex

Post-increment in assignment to reference c++

核能气质少年 提交于 2020-01-17 05:41:40
问题 Assume I have this code: int i = 2; int &ref = i++; Now, I understand that reference can not be initiaizied with rvalue, but I can not understand why ref isn't initialized with lvalue, meaning here, i , and after that i incremented. Moreover, in the following case: int i = 2; const int &ref = i++; cout << ref << endl; 2 will be printed, and it means that ref initialized with i before increment, i.e. initialized with lval. After that ref is incremented, but ref is const. Can someone explain me

SSIS and Microsoft.Exchange.WebServices

隐身守侯 提交于 2020-01-17 05:02:10
问题 I am writing an SSIS package that has required me to use the Microsoft.Exchange.WebServices DLL. I have imported it into the VB Script Task where it is referenced from the following location: C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebService.dll The script task seems to 'like' it in so much that I have imported the Namespace and am able to declare the ExchangeService as an object. However, when it comes to running the package (both compiled and in debug) I get

Cross referencing structs in C

[亡魂溺海] 提交于 2020-01-17 04:37:11
问题 Is there a way to create two structs that make a reference to each other? Example: struct str1 { struct str1* ptr1; struct str2* ptr2; } struct str2 { struct str1* ptr1; struct str2* ptr2; } 回答1: struct str2; // put a forward reference to str2 here struct str1 { struct str1* s1; struct str2* s2; }; struct str2 { struct str1* s1; struct str2* s2; }; int main() { struct str1 s1; struct str2 s2; s1.s1 = &s1; s1.s2 = &s2; s2.s1 = &s1; s2.s2 = &s2; return 0; } 回答2: typedef struct str1 str1_t;

Change the reference of a cell in excel?

不问归期 提交于 2020-01-17 03:22:45
问题 Maybe you guys could help me because I'm stumped. Here are some pictures to help illustrate my problem: As you can see, D1 is "referencing" B1. However, because I'm using the INDIRECT function, the actual reference is C1 and the following occurs: The blue reference box is on C1 and not B1. Is there any way to change the blue box so that it surrounds the actual cell being referenced (B1) without actually changing which cell is referenced by the INDIRECT function (C1)? Also, this is just an

Referencing entries of matrix in R within for loop

你说的曾经没有我的故事 提交于 2020-01-17 03:03:31
问题 Is there a way to reference a part of a matrix within a for loop? for (j in 1:x1) for (k in 1:x2) { matrix[j,8k-6:8k+1] <- AlleleFreq.t1[k,1:8] } } I get an error message saying "unexpected symbol in "alldata.t1[j,8k". What is the correct syntax for preforming this sort of operation? Thank you. 回答1: use parens & * to multiply: 8k-6:8k+1 ~~~> (8*k-6):(8*k+1) the seq operator : takes precedence over arithmetic operators such as - Thus, without parens, you have (8*k) - c(6, 7, 8) + ((8*k) + 1)