declaration

What is an 'undeclared identifier' error and how do I fix it?

左心房为你撑大大i 提交于 2019-11-26 00:33:37
问题 What are undeclared identifier errors? What are common causes and how do I fix them? Example error texts: For the Visual Studio compiler: error C2065: \'cout\' : undeclared identifier For the GCC compiler: \'cout\' undeclared (first use in this function) 回答1: They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error: Missing header int main() { std::cout << "Hello world!" << std:

Define global variable in a JavaScript function

拟墨画扇 提交于 2019-11-25 23:57:52
问题 Is it possible to define a global variable in a JavaScript function? I want use the trailimage variable (declared in the makeObj function) in other functions. <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head id=\"Head1\" runat=\"server\"> <title></title> <script type=\"text/javascript\"> var offsetfrommouse = [10, -20]; var displayduration = 0; var obj_selected = 0; function makeObj(address) { **var trailimage = [address, 50, 50];** document.write(\'<img id=\"trailimageid\" src=\"\' +

Java: define terms initialization, declaration and assignment

孤街醉人 提交于 2019-11-25 23:49:24
问题 I find the defs circular, the subjects are defined by their verbs but the verbs are undefined! So how do you define them? The Circular Definitions initialization: to initialize a variable. It can be done at the time of declaration. assignment: to assign value to a variable. It can be done anywhere, only once with the final-identifier. declaration: to declare value to a variable. [update, trying to understand the topic with lambda calc] D(x type) = (λx.x is declared with type) A(y D(x type)) =

Declaring Multiple Variables in JavaScript

大兔子大兔子 提交于 2019-11-25 23:39:28
问题 In JavaScript, it is possible to declare multiple variables like this: var variable1 = \"Hello World!\"; var variable2 = \"Testing...\"; var variable3 = 42; ...or like this: var variable1 = \"Hello World!\", variable2 = \"Testing...\", variable3 = 42; Is one method better/faster than the other? 回答1: The first way is easier to maintain. Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations. With the second way, it is annoying to

What’s the difference between “Array()” and “[]” while declaring a JavaScript array?

自作多情 提交于 2019-11-25 22:56:48
问题 What\'s the real difference between declaring an array like this: var myArray = new Array(); and var myArray = []; 回答1: There is a difference, but there is no difference in that example. Using the more verbose method: new Array() does have one extra option in the parameters: if you pass a number to the constructor, you will get an array of that length: x = new Array(5); alert(x.length); // 5 To illustrate the different ways to create an array: var a = [], // these are the same b = new Array()

What is the difference between a definition and a declaration?

徘徊边缘 提交于 2019-11-25 22:51:37
问题 The meaning of both eludes me. 回答1: A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier. These are declarations: extern int bar; extern int g(int, int); double f(int, double); // extern can be omitted for function declarations class foo; // no extern allowed for type declarations A definition actually instantiates/implements this identifier. It's what the linker needs

Meaning of &#39;const&#39; last in a function declaration of a class?

柔情痞子 提交于 2019-11-25 22:19:28
问题 What is the meaning of const in declarations like these? The const confuses me. class foobar { public: operator int () const; const char* foo() const; }; 回答1: When you add the const keyword to a method the this pointer will essentially become a pointer to const object, and you cannot therefore change any member data. (Unless you use mutable , more on that later). The const keyword is part of the functions signature which means that you can implement two similar methods, one which is called

Cannot refer to a non-final variable inside an inner class defined in a different method

那年仲夏 提交于 2019-11-25 22:14:59
问题 Edited: I need to change the values of several variables as they run several times thorugh a timer. I need to keep updating the values with every iteration through the timer. I cannot set the values to final as that will prevent me from updating the values however I am getting the error I describe in the initial question below: I had previously written what is below: I am getting the error \"cannot refer to a non-final variable inside an inner class defined in a different method\". This is

What are forward declarations in C++?

╄→尐↘猪︶ㄣ 提交于 2019-11-25 21:40:15
问题 At: http://www.learncpp.com/cpp-tutorial/19-header-files/ The following is mentioned: add.cpp: int add(int x, int y) { return x + y; } main.cpp: #include <iostream> int add(int x, int y); // forward declaration using function prototype int main() { using namespace std; cout << \"The sum of 3 and 4 is \" << add(3, 4) << endl; return 0; } We used a forward declaration so that the compiler would know what \" add \" was when compiling main.cpp . As previously mentioned, writing forward

What happens to a declared, uninitialized variable in C? Does it have a value?

亡梦爱人 提交于 2019-11-25 21:38:40
问题 If in C I write: int num; Before I assign anything to num , is the value of num indeterminate? 回答1: Static variables (file scope and function static) are initialized to zero: int x; // zero int y = 0; // also zero void foo() { static int x; // also zero } Non-static variables (local variables) are indeterminate . Reading them prior to assigning a value results in undefined behavior. void foo() { int x; printf("%d", x); // the compiler is free to crash here } In practice, they tend to just