argument-passing

What are the differences between parameter definitions as (type& name), and (type* name)?

a 夏天 提交于 2019-12-21 17:03:27
问题 A very basic question, but still, it would be good to hear from C++ gurus out there. There are two rather similar ways to declare by-reference parameters in C++. 1) Using "asterisk": void DoOne(std::wstring* iData); 2) Using "ampersand": void DoTwo(std::wstring& iData); What are implications of each method? Are there any gotcha's in any case? Bonus #1: What would be a formal way to call method in #1 and #2? Are they both called "by-reference"? Bonus #2: std::wstring is used deliberately. What

Using callNextMethod() within accessor function in R

旧巷老猫 提交于 2019-12-21 12:22:36
问题 This is related to the following post Problems passing arguments with callNextMethod() in R I am writing accessors for two S4 classes, 'foo' and 'bar'. 'bar' inherits from foo and is extended only by a few slots. Instead of writing a full accessor function for objects of class 'bar' I want to pass the arguments to callNextMethod() when accessing a slot that is inherited by 'foo'. My code looks like this: foo <- setClass("foo", representation(x = "numeric", y = "numeric")) bar <- setClass("bar

Javascript Find argument passed to a function

非 Y 不嫁゛ 提交于 2019-12-21 09:13:41
问题 I am needing to find the argument passed to a function from the function. Let us suppose I have a function called foo : function foo() { var a = 3; var b = "hello"; var c = [0,4]; bar(a - b / c); bar(c * a + b); } function bar(arg) { alert(arg) } As it is now, of course, bar will always alert NaN . Inside of the function bar , I want to obtain the argument in the form it was originally passed. Furthermore, I want to be able to access the values of a , b , and c from the bar function. In other

Javascript Find argument passed to a function

坚强是说给别人听的谎言 提交于 2019-12-21 09:13:34
问题 I am needing to find the argument passed to a function from the function. Let us suppose I have a function called foo : function foo() { var a = 3; var b = "hello"; var c = [0,4]; bar(a - b / c); bar(c * a + b); } function bar(arg) { alert(arg) } As it is now, of course, bar will always alert NaN . Inside of the function bar , I want to obtain the argument in the form it was originally passed. Furthermore, I want to be able to access the values of a , b , and c from the bar function. In other

Argument forwarding in LLVM

ぃ、小莉子 提交于 2019-12-21 04:37:08
问题 I need some advice on "forwarding" arguments to a callee (in the LLVM-IR). Suppose I have a function F that is called at the beginning of all other functions in the module. From F I need to access (read) the arguments passed to its immediate caller. Right now to do this I box all arguments in the caller inside a struct and pass a i8* pointer to the struct to F , alongside an identifier telling which caller F is being called from. F has then a giant switch that branches to the appropriate

Problems passing arguments with callNextMethod() in R

故事扮演 提交于 2019-12-19 06:19:58
问题 My question: Why is callNextMethod() not passing arguments as expected to the next method? Situation: Say I have two hierarchical classes foo and bar ( bar is subclass of foo ) for which I have a method foobar that can dispatch for both classes (i.e., has methods for both classes). Furthermore, the method for the (sub)class bar calls the method for foo after some calculations with callNextMethod() . Both methods have the same additional argument (with default) that should be passed to the

Ruby: Automatically set instance variable as method argument?

时光总嘲笑我的痴心妄想 提交于 2019-12-19 05:37:16
问题 Are there any plans to implement ruby behavior similar to the CoffeeScript feature of specifying an instance variable name in a method argument list? Like class User def initialize(@name, age) # @name is set implicitly, but @age isn't. # the local variable "age" will be set, just like it currently works. end end I'm aware of this question: in Ruby can I automatically populate instance variables somehow in the initialize method? , but all the solutions (including my own) don't seem to fit the

call RMarkdown on command line using a.R that is passed a file

这一生的挚爱 提交于 2019-12-18 12:56:20
问题 In summary, I am using my script 'Graphs.R' on 'input_file1.txt' in RStudio to create a Rmd which I then knit to html. I would like to automate this process to run more files on the command line. So far, I can get the Rscript to run on the command line using: Rscript Graphs.R input_file1.txt I also know that I can create an .RMD file using: Rscript -e rmarkdown::render(Graphs.R) However, I would like to do the following: Rscript -e rmarkdown::render('Graphs.R input_file1.txt', 'output_file

javascript: pass an object as the argument to a onclick function inside string

北城以北 提交于 2019-12-18 12:15:28
问题 I would like to pass an object as parameter to an Onclick function inside a string. Something like follwing: function myfunction(obj,parentobj){ var o=document.createElement("div"); o.innerHTML='<input type="button" onclick="somelistener(' + obj + ')" />'; parentobj.appendChild(o.firstChild); } Obviously, this doesn't work. Anyone has any idea? THX! A more complete version, as suggested by @Austin <!DOCTYPE html> <html> <body> <style type="text/css"> </style> <p id="test">test</p> <p id=

Passing a class as an argument to a method in java

假如想象 提交于 2019-12-18 07:40:10
问题 I am writing a method were I would like to pass a class to a method, where a part of the code includes checking if the object is of a certain type. This is what I want (but which obviously doesn't work): private static class MyClass1 { /***/ } private static class MyClass2 { /***/ } private void someFunc() { /* some code */ methodName(MyClass1); methodName(MyClass2); } private void methodName(Class myClass) { Object obj; /* Complicated code to find obj in datastructure */ if (obj instanceof