function-parameter

C++ Compiler Error C2751 - What exactly causes it?

久未见 提交于 2019-12-24 06:29:51
问题 I am wrestling with the C2751 compiler error and don't quite understand what exactly causes it. The following little code produces the error: #include <iostream> class A { public: A () { std::cout << "A constructed" << std::endl; }; static A giveA () { return A (); } }; class B { public: B (const A& a) { std::cout << "B constructed" << std::endl; } }; int main () { B b1 = B (A::giveA ()); // works B b2 (B (A::giveA ())); // C2751 B b3 (A::giveA ()); // works } Compiler output:

PostgreSQL function with duplicate parameters

纵饮孤独 提交于 2019-12-23 09:11:30
问题 I stumbled upon a curious function signature in pg_catalog.pg_stat_get_activity : CREATE OR REPLACE FUNCTION pg_stat_get_activity( IN pid integer, OUT datid oid, OUT pid integer, -- more parameters...) RETURNS SETOF record AS 'pg_stat_get_activity' LANGUAGE internal STABLE COST 1 ROWS 100; This function declares the same parameter name twice, which is also reported from the information_schema . select parameter_mode, parameter_name from information_schema.parameters where specific_schema =

MATLAB: Is there a method to better organize functions for experiments?

偶尔善良 提交于 2019-12-21 05:08:20
问题 I will run a set of experiments. The main method evaluated has the following signature: [Model threshold] = detect(... TrainNeg, TrainPos, nf, nT, factors, ... removeEachStage, applyEstEachStage, removeFeatures); where removeEachStage , applyEstEachStage , and removeFeatures are booleans. You can see that if I reverse the order of any of these boolean parameters I may get wrong results. Is there a method in MATLAB that allows better organization in order to minimize this kind of error? Or is

Setting local variables to a function instead of using globals optimize the function

岁酱吖の 提交于 2019-12-20 01:35:27
问题 In the documentation for the itertools module I found this comment def dotproduct(vec1, vec2): return sum(imap(operator.mul, vec1, vec2)) Note, many of the above recipes can be optimized by replacing global lookups with local variables defined as default values. For example, the dotproduct recipe can be written as: def dotproduct(vec1, vec2, sum=sum, imap=imap, mul=operator.mul): return sum(imap(mul, vec1, vec2)) How is it?. Is there a practical noticeable speed-up (that could balance the

C# enums as function parameters?

核能气质少年 提交于 2019-12-18 18:47:23
问题 Can you pass a standard c# enum as a parameter? For example: enum e1 { //... } enum e2 { //... } public void test() { myFunc( e1 ); myFunc( e2 ); } public void myFunc( Enum e ) { // Iterate through all the values in e } By doing this I hope to retrieve all the names within any given enum. What would the Iteration code look like? 回答1: This! public void Foo(Enum e) { var names = Enum.GetNames(e.GetType()); foreach (var name in names) { // do something! } } EDIT: My bad, you did say iterate .

Why is the function argument not overwritten on creating variable of same name inside the function?

不羁岁月 提交于 2019-12-18 18:42:13
问题 var a = 'why is this not undefined?'; function checkScope(a) { var a; console.log(a); } checkScope(a); Javascript is functional scope language, right? When I declare a new variable just inside the function that uses the same name as the functional argument, why does the newly defined variable still hold the same data as the argument? I thought it should be undefined? 回答1: var a; is actually a variable declaration statement. When the function is defined, all the variables declared in it, are

Using function arguments as local variables

我的未来我决定 提交于 2019-12-18 12:15:26
问题 Something like this (yes, this doesn't deal with some edge cases - that's not the point): int CountDigits(int num) { int count = 1; while (num >= 10) { count++; num /= 10; } return count; } What's your opinion about this? That is, using function arguments as local variables. Both are placed on the stack, and pretty much identical performance wise, I'm wondering about the best-practices aspects of this. I feel like an idiot when I add an additional and quite redundant line to that function

When a function has a specific-size array parameter, why is it replaced with a pointer?

拈花ヽ惹草 提交于 2019-12-16 18:34:28
问题 Given the following program, #include <iostream> using namespace std; void foo( char a[100] ) { cout << "foo() " << sizeof( a ) << endl; } int main() { char bar[100] = { 0 }; cout << "main() " << sizeof( bar ) << endl; foo( bar ); return 0; } outputs main() 100 foo() 4 Why is the array passed as a pointer to the first element? Is it a heritage from C? What does the standard say? Why is the strict type-safety of C++ dropped? 回答1: Yes it's inherited from C. The function: void foo ( char a[100]

scala way to define functions accepting a List of different numeric types

倖福魔咒の 提交于 2019-12-14 00:23:27
问题 I have the following problem: I have a function which takes a List[Double] as parameter, performs some arithmetic operations on the elements of the list and than return the result. I would like the function also to accept List[Int]. Here is an example: def f(l: List[Double]) = { var s = 0.0 for (i <- l) s += i s } val l1 = List(1.0, 2.0, 3.0) val l2 = List(1, 2, 3) println(f(l1)) println(f(l2)) Of course the second println fails since f requires List[Double] and not List[Int]. Also note the

Passing values to a function from within a function in python

三世轮回 提交于 2019-12-13 23:48:12
问题 I need to pass values from one function to the next from within the function. For example (my IRC bot programmed to respond to commands in the channel): def check_perms(nick,chan,cmd): sql = "SELECT `"+ cmd +"` FROM permissions WHERE nick = '"+ nick +"' and chan = '"+ chan +"'" # This returns 0 #sql = "SELECT `restart` FROM permissions WHERE nick = 'Me' and chan = '#mychan'" # this works as intended cursor.execute(sql) result = cursor.fetchall() for row in result: if (row[0] == 1): # Nick