global-variables

Initialization of object static members

瘦欲@ 提交于 2019-12-31 04:28:05
问题 Static members confuse me sometimes. I understand how to initialize a simple built in type such as int with something along the lines of int myClass::statVar = 10; , which you place in a .cpp file, but I have something of the following sort: class myClass { public: // Some methods... protected: static RandomGenerator itsGenerator; } The basic idea is simple enough: myClass needs access to a random generator for one of its member functions. I also can have only a few instances of the generator

Making global var from inside a function in PHP

蹲街弑〆低调 提交于 2019-12-31 04:27:06
问题 I am trying to define dynamically variables. I am using a function for this, but I don't know how to define the new var as global (because it never created before the function). is that possible ? Thanks. edit ok, this is what I've built. is it that dangerous ? function extract_values($row) { foreach ($row as $key => $value){ global $$key; $$key = $value; } } and then I'm trying to make my life easier like that: $result = mysql_query("SELECT first_name, last_name, address FROM users ORDER BY

Global variables in Visual C#

非 Y 不嫁゛ 提交于 2019-12-31 03:35:07
问题 How do I declare global variables in Visual C#? 回答1: How about this public static class Globals { public static int GlobalInt { get; set; } } Just be aware this isn't thread safe. Access like Globals.GlobalInt This is probably another discussion, but in general globals aren't really needed in traditional OO development. I would take a step back and look at why you think you need a global variable. There might be a better design. 回答2: A public static field is probably the closest you will get

PHP Templating

為{幸葍}努か 提交于 2019-12-31 02:44:07
问题 I'm writing a simple templating layer in PHP but I've got myself a little stuck. Here's how it works at the moment: Firstly I use fetch_template to load the template contents from the database - this works (and I collect all the templates at startup if you're interested). I use PHP variables in my template code and in the logic - e.g.: // PHP: $name = 'Ross'; // Tpl: <p>Hello, my name is $name.</p> I then use output_template (below) to parse through the variables in the template and replace

Python: How to use named variables from one function in other functions

北战南征 提交于 2019-12-31 01:48:19
问题 I'm a newbie programmer trying to make a program, using Python 3.3.2, that has a main() function which calls function1() , then loops function2() and function3() . My code generally looks like this: def function1(): print("hello") def function2(): name = input("Enter name: ") def function3(): print(name) def main(): function1() while True: funtion2() function3() if name == "": break main() Currently, I get the following error when I run the program and enter a name: NameError: global name

Is a global pointer initialized to zero?

ε祈祈猫儿з 提交于 2019-12-30 20:18:11
问题 I was wondering what the cpp standard says about global initialization. I have found this answer helpful, but there was no mention of a pointer type. Is there a guarantee that this will work? char* myptr int main() { if (myptr == NULL) { std::cout << "All good!" << std::endl; } } 回答1: Yes, a pointer defined at namespace scope (global namespace in your case) is guaranteed to be initialized to the correct null pointer value of the type. For the standard references, 3.6.2[basic.start.init]/2

Python - User input for name of a variable to pass as an argument to a function

痞子三分冷 提交于 2019-12-30 11:02:32
问题 I have a question here which is based around user input to scripts and passing this user-input to functions. I have a script, within which I have defined a function. What I want the script to do is take user input to pass as arguments to the function. However, one of the things I want to pass to the function is the name of an argument rather than the argument itself. The user has the choice of using a variety of different lists to input to the function, and what I wanted was to get the user

Can't find variable: Buffer

巧了我就是萌 提交于 2019-12-30 07:31:42
问题 I'm trying to use node modules in my react-native app, and I'm taking the ReactNativify approach here. I'm all set up now, and I got the crypto package to load in fine. However when I added in eth-lightwallet things have been getting weird. Every since I added that package in, npm hasn't been installing dependancies of anything. Meaning I've had to add them in manually. And everytime I install a dependency somehow related to eth-lightwallet, that module is uninstalled. Although tedious and

How to pass variables into NodeJS modules?

不羁的心 提交于 2019-12-30 06:08:47
问题 In one of my JS files I include another one. How can I set variables in the included module? I thought doing something like this would work var mymodule = require('mymodule.js'); mymodule.myvariable = 'test'; And then in mymodule this.myvariable === 'test'; But this doesn't work, it's undefined . What are the various options for passing a value into a module? I could just add the variable as a parameter to every function I call in mymodule, but that isn't ideal. Is there a way to do it

How to pass variables into NodeJS modules?

馋奶兔 提交于 2019-12-30 06:07:21
问题 In one of my JS files I include another one. How can I set variables in the included module? I thought doing something like this would work var mymodule = require('mymodule.js'); mymodule.myvariable = 'test'; And then in mymodule this.myvariable === 'test'; But this doesn't work, it's undefined . What are the various options for passing a value into a module? I could just add the variable as a parameter to every function I call in mymodule, but that isn't ideal. Is there a way to do it