declaration

Why are variables declared with their interface name in Java? [duplicate]

本小妞迷上赌 提交于 2019-11-26 06:46:45
问题 This question already has answers here : What does it mean to “program to an interface”? (31 answers) Closed 2 years ago . This is a real beginner question (I\'m still learning the Java basics). I can (sort of) understand why methods would return a List<String> rather than an ArrayList<String>, or why they would accept a List parameter rather than an ArrayList. If it makes no difference to the method (i.e., if no special methods from ArrayList are required), this would make the method more

How do I understand complicated function declarations?

梦想的初衷 提交于 2019-11-26 06:46:31
How do I understand following complicated declarations? char (*(*f())[])(); char (*(*X[3])())[5]; void (*f)(int,void (*)()); char far *far *ptr; typedef void (*pfun)(int,float); int **(*f)(int**,int**(*)(int **,int **)); As others have pointed out, cdecl is the right tool for the job. If you want to understand that kind of declaration without help from cdecl, try reading from the inside out and right to left Taking one random example from your list char (*(*X[3])())[5]; Start at X, which is the identifier being declared/defined (and the innermost identifier): char (*(*X[3])())[5]; ^ X is X[3]

Spiral rule and &#39;declaration follows usage&#39; for parsing C and C++ declarations

烂漫一生 提交于 2019-11-26 06:38:18
问题 This question follows this other question about C declarations. Reading the answer to this question, I read about the spiral rule and I also understood what \"declaration follows usage\" means. Ok so far. But then I read this declaration: char *(*(*a[N])())(); and I was wondering how to parse it with the \"declaration follows usage\" \'rule\'. Especially for the array part. What I read is: (*(*a[N])()) is a function () returning a char * , then, dereferencing the following (*a[N])() // 1 is

How does the Java array argument declaration syntax “…” work?

a 夏天 提交于 2019-11-26 06:31:46
问题 I have been writing java for a while, and today I encountered the following declaration: public static void main(String... args) { } Note the \"dot dot dot\" in the array declaration, rather than the usual bracket []. Clearly it works. In fact I wrote a small test and verified it works. So, I pulled the java grammar to see where this syntax of argument declaration is, but did not find anything. So to the experts out there, how does this work? Is it part of the grammar? Also, while I can

What&#39;s the _ underscore representative of in Swift References?

会有一股神秘感。 提交于 2019-11-26 05:59:34
问题 In the reference section of Apple\'s docs there\'s lots of instances of this sort of thing: func runAction(_ action : SKAction!) The Objective-C \'equivalent\' of this is: - (void)runAction:(SKAction *) action It strikes me that it\'s probably important that (in the Swift reference) there\'s a space after the underscore and \"action\" is written in italics. But I can\'t figure out what this is trying to convey. So perhaps the question is... is there a reference for the conventions used in the

Why does “extern const int n;” not work as expected?

孤街浪徒 提交于 2019-11-26 05:33:03
问题 My project consists of only two source files: a.cpp: const int n = 8; b.cpp: extern const int n; int main() { // error LNK2001: unresolved external symbol \"int const n\" (?n@@3HB) int m = n; } I know there are several methods to make it work; however, I just wonder WHY it does\'t work? 回答1: It's because const implies internal linkage by default, so your "definition" isn't visible outside of the translation unit where it appears. In this case, by far the best solution is to put the

Meaning of = delete after function declaration

别等时光非礼了梦想. 提交于 2019-11-26 04:57:47
问题 class my_class { ... my_class(my_class const &) = delete; ... }; What does = delete mean in that context? Are there any other \"modifiers\" (other than = 0 and = delete )? 回答1: Deleting a function is a C++11 feature: The common idiom of "prohibiting copying" can now be expressed directly: class X { // ... X& operator=(const X&) = delete; // Disallow copying X(const X&) = delete; }; [...] The "delete" mechanism can be used for any function. For example, we can eliminate an undesired conversion

Declaring and initializing variables within Java switches

。_饼干妹妹 提交于 2019-11-26 04:46:03
问题 I have a crazy question about Java switches. int key = 2; switch (key) { case 1: int value = 1; break; case 2: value = 2; System.out.println(value); break; default: break; } Scenario 1 - When the key is two it successfully print the value as 2. Scenario 2 - When I\'m going to comment value = 2 in case 2: it squawks saying the The local variable value may not have been initialized . Questions : Scenario 1 : If the execution flow doesn\'t go to case 1: (when the key = 2 ), then how does it know

How to declare variable and use it in the same Oracle SQL script?

独自空忆成欢 提交于 2019-11-26 04:36:49
问题 I want to write reusable code and need to declare some variables at the beginning and reuse them in the script, such as: DEFINE stupidvar = \'stupidvarcontent\'; SELECT stupiddata FROM stupidtable WHERE stupidcolumn = &stupidvar; How can I declare a variable and reuse it in statements that follow such as in using it SQLDeveloper. Attempts Use a DECLARE section and insert the following SELECT statement in BEGIN and END; . Acces the variable using &stupidvar . Use the keyword DEFINE and access

The spiral rule about declarations — when is it in error?

余生颓废 提交于 2019-11-26 04:26:40
问题 I recently learned the spiral rule for deobfuscating complex declarations, that must have been written with a series of typedefs. However, the following comment alarms me: A frequently cited simplification, which only works for a few simple cases. I do not find void (*signal(int, void (*fp)(int)))(int); a \"simple case\". Which is all the more alarming, by the way. So, my question is, in which situations will I be correct to apply the rule, and in which it would be in error? 回答1: Basically