parameters

Accessing shell script arguments by index

那年仲夏 提交于 2019-12-17 19:58:09
问题 I'm sure this is a no-brainer when you're into shell programming. Unfortunately I'm not and I'm having a pretty hard time ... I need to verify arguments passed to a shell script. I also want to store all parameters passed in an array as I need further separation later. I have an argument "-o" which must be followed by either 0 or 1. Thus, I want to check if the following argument is valid. Here's what I tried: # Loop over all arguments for i in "$@" do # Check if there is a "-" as first

What does it mean to return a reference?

送分小仙女□ 提交于 2019-12-17 19:47:30
问题 I understand the concept of references in C++, and I understand what they do when used in function parameters, but I am still very much confused on how they work with return types. For example, when used in parameters, this code: int main (void) { int foo = 42; doit(foo); } void doit (int& value) { value = 24; } is similar to this code: int main (void) { int foo = 42; doit(&foo); } void doit (int* value) { *value = 24; } (knowing that the compiler will automatically put an asterisk in front

How to access nested parameter values in Symfony2?

风格不统一 提交于 2019-12-17 19:34:00
问题 I created a parameter in my parameters.yml file: parameters: category: var: test How can I access this parameter in my config.yml ? For example, I want to pass this parameter to all my twig files as a global twig variable: twig: globals: my_var: %category.var% # throws ParameterNotFoundException 回答1: In all the symfony config files I've seen, the entries under 'parameters:' have always been fully qualified. I don't fully understand why this is but it may help you to write the entries in your

C# Generic method and dynamic type problem [duplicate]

这一生的挚爱 提交于 2019-12-17 19:29:18
问题 This question already has answers here : Calling a generic method with a dynamic type [duplicate] (5 answers) Closed 6 years ago . I have a generic method declared as follow : public void Duplicate<EntityType>() { ... } So, generally to use it I simply need to do say : myObject.Duplicate<int>() But here, what I'd like to do is pass the type by a variable, but it doesn't work, here is how I try to do this : Type myType = anObject.GetType(); myObject.Duplicate<myType>(); If someone can help me

Why does Go allow compilation of unused function parameters?

泄露秘密 提交于 2019-12-17 19:15:30
问题 One of the more notable aspects of Go when coming from C is that the compiler will not build your program if there is an unused variable declared inside of it. So why, then, is this program building if there is an unused parameter declared in a function? func main() { print(computron(3, -3)); } func computron(param_a int, param_b int) int { return 3 * param_a; } 回答1: There's no official reason, but the reason given on golang-nuts is: Unused variables are always a programming error, whereas it

How to get the value of a method argument via reflection in Java?

筅森魡賤 提交于 2019-12-17 18:57:53
问题 Consider this code: public void example(String s, int i, @Foo Bar bar) { /* ... */ } I'm interested in the value of the argument annotated with @Foo . Assume that I have already figured out via reflection (with Method#getParameterAnnotations() ) which method parameter has the @Foo annotation. (I know it is the third parameter of the parameter list.) How can I now retrieve the value of bar for further usage? 回答1: You can't. Reflection does not have access to local variables, including method

Difference between const declarations in C++

眉间皱痕 提交于 2019-12-17 18:47:11
问题 What is the difference between void func(const Class *myClass) and void func(Class *const myClass) See also: C++ const question How many and which are the uses of "const" in C++? and probably others... 回答1: The difference is that for void func(const Class *myClass) You point to a class that you cannot change because it is const. But you can modify the myClass pointer (let it point to another class; this don't have any side effects to the caller because it's pointer is copied, it only changes

Should I use the same name for a member variable and a function parameter in C++

♀尐吖头ヾ 提交于 2019-12-17 17:47:06
问题 I am wondering if it is a good practice to use the same name for both a member variable and a function parameter in C++. I come from a Java background, where this was common. I am wondering if in C++ there are drawbacks doing the following (the code works): class Player { public: void setState(PlayerState *state) { this->state = state; } private: PlayerState *state; } Thank you for the answers. As I understand while it works, a better practice would be to put some kind of marker to

C Parameter Array Declarators [duplicate]

依然范特西╮ 提交于 2019-12-17 17:34:47
问题 This question already has an answer here : What is the purpose of static keyword in array parameter of function like “char s[static 10]”? (1 answer) Closed 5 years ago . In C99 there are variable-length arrays, and there can be static qualifiers (and type qualifiers) in parameter array declarators: void f(int i, int *a); void f(int i, int a[]); void f(int i, int a[i]); void f(int i, int a[*]); // Only allowed in function prototypes. void f(int i, int a[static i]); Since array function

Send additional parameter to Ajax event listener

元气小坏坏 提交于 2019-12-17 16:57:12
问题 I am having a ajax listener who should redirect to item view page. However since I am using generic type as model I would like to specify additionally in my common datatable controller what is the view with a second parameter. Unfortunately one can choose between two listener approaches one using event parameter which helps identifying the object and the second one gives you the opportunity to send free param but lacks the event. template : <p:dataTable value="#{aObj.objList}" var="item" ....