Menu
  • HOME
  • TAGS

Difference between static and const variables [duplicate]

c#,variables,static,const,global

const and readonly perform a similar function on data members, but they have a few important differences. A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. The...

Encapsulate dependency/coupling and hierachy of static data list

c#,static,decoupling

Get rid of the "abstract class which describes the interface" and use an actual interface. interface IHaveData { int[] getSomeData(); } Now this frees you up to implement registrations however you want. Here's one simple way that fits with your initial code: class BaseData { private static readonly List<IHaveData> collection...

“Only static constant integral variables may be initialized within a class ”

c++,class,variables,static

In versions of C++ prior to C++11, the language standard simply doesn't allow you to perform a static variable definition inside the class declaration. In other words, You can't initialize it because it isn't constant. Since it can change during execution, the compiler needs some memory allocated somewhere to actually...

Emergency: “error: non-static variable this cannot be referenced from a static context” [duplicate]

java,static,this,non-static

You need to create an instance of MainApp in main Instead of having all your code in your main(), you need to transfer that code to a new private void run() method (or whatever you want to call it). public static void main(String[] args) { new MainApp().run(); } Now, since...

Static variables and memory consumption

objective-c,memory,static

By definition, there is only one copy of a static variable. No matter how many instances of your class you have, there will only be one copy of the someDictionary. It will get initialized once and every time the method is used, regardless of class instance, the same exact dictionary...

How to fill HashMap object only once for program?

java,static,hashmap,instantiation

You can call the getAnimalNameTranslations method from your static initializer block, which would be executed once, when the class is initialized. You'll have to add a static member that holds the Map returned by the method. For example : private static HashMap<String, String> animalNameTranslations; static { animalNameTranslations = getAnimalNameTranslations ();...

Calling a Static Method In Main

java,methods,static,rational

You can call it like this: public class Main { public static void main(String[] args) { Rational rational1 = new Rational(1,2); Rational rational2 = new Rational(1,2); Rational result = Rational.multiply(rational1, rational2); } } ...

How to compile fortran code to run without gfortran installed

osx,static,compilation,makefile,fortran

The current version of the option is -static-libgfortran. This means that the Fortran specific libraries of gfortran will be included into the executable. These are libraries are automatically found for a good installation of gfortran. This should produce an executable that should run on other computers with the same OS,...

Using variables / Static variables to 'name' values to aid readability

java,static,final

Imagine you have 100 of MyObject objects and all members are final and static.This means that all of these 100 objects have same nonchangeable static variables because of final.so you can't change these members in other 99 objects.So you can't use static and final together in your situtation. think about...

Defining Macros that are equal to functions that return objects in C++

c++,static,macros,singleton

The problem is that you defined TheUniverse as Universe::GetInstance();, with a semicolon. Therefore, after macros are processed, you get Universe::GetInstance();.Initialize(); which is obviously not what you want. To fix the problem simply remove the semicolon in the macro definition.

C++11 MinGW 4.9.1 shared_ptr and const static class field result “Undefined reference”

c++,c++11,static,const,mingw32

This is because CItem::CAP is odr-used by std::make_shared (emphasis mine): Informally, an object is odr-used if its address is taken, or a reference is bound to it, and a function is odr-used if a function call to it is made or its address is taken. If an object or a...

C - how to keep variable

c,static,int

The error you got has nothing to do with the scope of buf. It refers to the system function which expects only one parameter: int system(const char *command) Hope I helped....

Static interface equivalent C#

c#,inheritance,interface,static

It seems you want to supply some meta-information along with the subclasses of TableRow; meta-information that can be retrieved without instantiating the particular subclass. While .NET lacks static interfaces and static polymorphism, this can (to some extent, see below) be solved with custom attributes. In other words, you can define...

Are static variables initialised from a file initialised only once

java,static

Check Java first. Below is java 8; and I used javafx.scene.paint.Color as Oracle sees JavaFX as successor to AWT/Swing. It can do 148 color names. First a test on your colors: String[] colorNames = { "aquamarine", "Aquamarine", "AntiqueWhite" }; // List with color as hex, with alpha component as FF...

How to show posts onto a static page

ruby-on-rails,static,posts

Assuming your root route points to your landing page, root 'welcome#index' In controller, fetch the image records you want to show on the landing page, class WelcomeController < ApplicationController def index @images = Image.last(10) end end Use them in views, - @images.each do |image| # put them in img tag...

Strict Standards: Non-static method should not be called statically, assuming $this from incompatible context

php,static,standards,strict,non-static

Just change your method type, add the static keyword and call as you are doing now. public function getMapper() { if (null === self::$__mapper) { self::setMapper(new Vox_Model_Setting_Mapper()); } return self::$__mapper; } to public static function getMapper() { # see extra static keyword if (null === self::$__mapper) { self::setMapper(new Vox_Model_Setting_Mapper()); }...

References - Why do the following two programs produce different output?

c++,reference,static,output

In the first case, fun() returns a reference to the same variable no matter how many times you call it. In the second case, fun() returns a dangling reference to a different variable on every call. The reference is not valid after the function returns. When you use fun() =...

Is it possible to initialize a static member variable after running the main?

c++,static

No, it isn't possible to initialize it, but there should be no reason why you can't just call a static setter function that assigns a value to i in run-time. This is the best method. Or you alternatively, you could make it so that the constructor always initializes the variable:...

return reference of static member variable c++

c++,reference,static

If POS is declared static then its lifetime is the lifetime of the program, and so returning a reference to it is safe.

django how to include javascript in template

javascript,python,django,static,include

urls.py from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)), ] settings.py STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) STATIC_URL = '/static/' # remove STATIC_ROOT base.html Your title tag was not closed. <!DOCTYPE html> <head> {% load static %} <script src="{% static 'app.js' %}"></script> <title>Site</title> </head>...

How to get a variable from another class without calling a constructor?

java,constructor,static,libgdx,box2d

If you want the body of an object (player) which participates in collision then you can simply get it from the fixture, using: contact.getFixtureA().getBody(); Else if you have a custom class named "Player" and you want the object of that class which participates in the collision, you can save the...

Is there a way to access the variables/fetch the assigned values of the caller class in a method of the called class?

java,class,static

No, this is not possible. Especially since a is a local variable. If a had been a field, there might have been a remote possibility to solve this using some reflection / stack trace hack....

Is this thread-safe in Java?

java,static,thread-safety

Yes, that is thread safe. static initializer blocks are run when the class is initialized and that is done behind a lock. So mySet is initialized fully before it is published (made available). All threads will see it fully constructed.

Android:I do not understand: static { foo();} [duplicate]

java,android,static,static-block

That's a static block. It is executed the first time that class is referenced on your code, and it is calling a static method called foo(). You can find more about the static block here. As mentioned by @CommonsWare, you can initialize a static field in two different ways, inline...

How can I use a non-static (dynamic instance) object as return for a static method in Java? [closed]

java,static,return

Looking at the error you have, your question probably misses a bit of code, it is probably like: public class SomeClass { public class UserData { .... } public static UserData decodeText(String codeString) { UserData data = new UserData(); .... } } Inner Classes So you are using the concept...

Perl: Static vs Package methods

perl,static,package

First, a functional point: If a 2nd Class is create that inherits from My::Package, Child::Class::Sub1() will be undefined, and if Sub1 is written as a non-OO subroutine, Child::Class->Sub1() will ignore the fact that it's being called from Child::Class. As such, for the sake of the programmers using your module, you'll...

Javascript static vs instance, prototype keyword

javascript,static,prototype

In Javascript, any function is also an object, so any function can have properties assigned to it. That's what your first block of code is doing. It is just assigning properties to the CookieHandler function. If CookieHandler is meant as an object definition, then though not exactly identical, these are...

How do you link to site-wide static files in django 1.8?

css,django,static

Try to change os.path.join(BASE_DIR, '/MySite/static/') to os.path.join(BASE_DIR, 'MySite/static'), i. e. remove forwarding /. I guess the reason is how os.path.join works >>> os.path.join('/foo', '/bar') '/bar' >>> os.path.join('/foo', 'bar') '/foo/bar' ...

java test objects with static field

java,unit-testing,static

I don't think this is well written. If I interpret this correctly, you want a unique projectid associated with each instance that is calculated from the static count. Change your code like this: class Project() { private static int id; private int projectid; public Project(fileds) { // This notation makes...

What is the meaning of “static” in parameters array types in C?

arrays,function,parameters,static,c99

This C99 notation, void foo(double A[static 10]), means that the function can assume that A points to 10 valid arguments (from *A to A[9]). The notation makes programs more informative, helping compilers to both optimize the code generated for the function foo and to check that it is called correctly...

Why do two programs have forward referencing errors while the third does not?

java,static,instance,forward

This is covered by section 8.3.3 of the JLS: Use of class variables whose declarations appear textually after the use is sometimes restricted, even though these class variables are in scope (§6.3). Specifically, it is a compile-time error if all of the following are true: The declaration of a class...

Accessing non static members inside static method via passed pointer

c++,multithreading,static,this

args->myPublicMethod(); //Is this legal and valid? No. That is neither legal nor valid. However, you can use: reinterpret_cast<MyClass*>(args)->myPublicMethod(); You can access a private member function of a class from a static member function. So, you can access a private member of the class using: reinterpret_cast<MyClass*>(args)->myPrivateMember; Another SO question and its...

Is it possible to serve a static html page at the root of a django project?

python,html,django,static,pythonanywhere

Of course you can. In cases where I just need to render a template, I use a TemplateView. Example: url(r'^$', TemplateView.as_view(template_name='your_template.html')) I usually order my URL patterns from most specific to least specific to avoid unexpected matches: from django.views.generic import TemplateView urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^MyApp/', include('MyApp.urls')), url(r'^$', TemplateView.as_view(template_name='your_template.html')),...

Java dynamic, static casting

java,dynamic,static,polymorphism

The idea behind static cast and dynamic cast is related to the moment a type decision needs to be made. If it needs to be made by the compiler then it's static cast. If the compiler postpones the decision to runtime then it's dynamic cast. So, your first observation is...

PHP - Using a Double colon with a class varible

php,class,static,scope-resolution

You can't do that actually. Within a class instance you cannot use $this->var to reference another class. You can, however, assign it to another local variable and have that work public function index() { $var = $this->model; $woot = $var::find(''); var_dump($woot); } ...

Placing a global constant array into `.rodata` section

c,gcc,static

There is no portable way to put data into the .rodata section because even the existence of such a section is implementation-dependent. With that said, you could consider approaching your problem like this: extern const int * const data; /* ... */ static const int rodata[] = {0,1,2,....}; const int...

How to omit creating static Map for data caching?

java,caching,static,hashmap

You can use Google guava for this type of caching: Cache<String, List<String>> cachedXpaths = CacheBuilder.newBuilder() .expireAfterWrite(3, TimeUnit.MINUTES) .maximumSize(1000) .concurrencyLevel(5) .weakKeys() .build( new CacheLoader<String, List<String>>() { // Call load method when there is a new key public List<String> load(String key) throws Exception { // Sample custom method to add a new...

Implementing a Command Design Pattern with static methods C#

c#,design-patterns,design,static

Delegates are C#'s built-in implementation of the command pattern. Why re-invent the wheel; use delegates, which support static, pure functions automatically. So you have an event system and those events invoke delegates. You need those delegates to have state though, without creating instances of some class. That's where closures come...

How can I differentiate static functions with nm or readelf output in C

c,static,nm,symbol-table

Your question assumes that, given an executable, you can always discover the names of the static (local) functions that were compiled into it, using nm or another tool. Thus you will be able to see when two or more such names are the same and to raise the question of...

Why is a static method considered a method?

java,methods,static,terminology

This quote from 8.4.3.2 may help: A method that is declared static is called a class method. A method that is not declared static is called an instance method [...]. Class methods: associated with a class. Instance methods: associated with an instance. Java just wants you to "think object-oriented". Also,...

Static fields in Android

java,android,static

Is it bad practice to use static field for transfer data between activities and fragments? Generally speaking, yes. There are certainly Android patterns for using static data members, but for "transfer data", they are rarely used, for all the classic reasons why global variables are considered to be poor...

Alternatives to mock an static method

java,junit,static,mocking,mockito

While putting a null pointer check in the static method would avoid the NPE being thrown; it it a bit of a code smell. I would suggest that the jTextArea be declared as non-static which in turns implies that the printInMain method would also be non-static. This then leads to...

Static class variables in Python — Lists & Objects [duplicate]

python,list,static,static-variables,class-variables

The Key word self makes them independent as if you are saying, self.name, belongs to the current instance of box() class: class box (): def __init__ (self, name): self.name = name self.contents = [] def store (self, junk): self.contents.append(junk) def open (self): return self.contents ...

Why using static classes to share global data is not a good practice? [closed]

c#,wpf,static,shared-data

If it is only about parameters setup, don't see any problem with sharing them among different parts of application, instead of have multiple copies of the same data. It still stays on shoulders of SOLID principles, as the responsibility of that class is holding parameter/configuration options. If you have also...

using subclass's static variable in superclass

c++,variables,static,subclass

You may put definition of constructor Class1 after Class2 definition: class Class1 { public: Class1(); }; class Class2: public Class1 { public: static int counter; }; int Class2::counter = 0; Class1::Class1() { Class2::counter++;} Live demo...

Passing values from an array to child template in meteor

arrays,templates,meteor,static,nested

There's no need to explicitly pass the currently iterated over item to the child template, it is automatically done by Spacebars. Inside your intervalIcon template, you can refer to the item value using {{this}}. <template name="intervalIcon"> <p>{{this}}</p> </template> You can also give the interval value a name by replacing your...

Is there a way to get the object which called my static method as an instance method? [duplicate]

java,static

No, there is no way for the method to know whether it was called on a class or on an instance (at the JVM level there is no difference), and there is no way to get the instance that the method was called on. The term for this kind of...

about usage of “static”, really basic

c,static

in response to Frank Hao comment Global int a is initialized as 0. for i = 0; first call fun(2) { return ((1)+(3)+(4)); } for i = 1; second call fun(2) { return ((2)+(3)+(5)); } ...

Access static method from static variable

python,python-2.7,static

The problem is that the class "A" doesn't exist yet at the moment your vatiable pth is declared, so the evaluation fails. How about declaring it right after? import os, platform class A(object): @staticmethod def getRoot(): return 'C:\\' if platform.system() == 'Windows' else '/' A.pth = os.path.join(A.getRoot(), 'some', 'path') An...

How to gain Static Constructor's functionality in JAVA?

java,constructor,static,static-constructor

You may use static initialization block like this - class SimpleClass { static{ } } The static block only gets called once, no matter how many objects of that type is being created. You may see this link for more details. Update: static initialization block is called only when the...

Initialisation of Static variables in java

java,static

If you are concerned about the order of initialization/execution, here is what is going to happen (I believe it is not very accurate, just giving you an idea): JVM is asked to run the Java app (assume your class is named) Foo, it tries to load Foo class from classpath...

Using NON static class Methods Without reference

java,object,methods,reference,static

If Calendar was following a fluent builder pattern, where i.e. the add method was adding, then returning the mutated instance, you would be able to. You're not, because Calendar#add returns void. But don't be fooled: Calendar.getInstance() does create an instance as indicated - you're just not assigning it to a...

static initialization of members of class of the same class in c++ [duplicate]

c++,static

Since your constants reside inside Color, you have to define them like this: const Color Color::CLEAR(0, 0, 0, 0); // ^^^^^^^ // Qualification of static class member. // // Instead of: Color CLEAR(0, 0, 0, 0); ...

how to increment value of string variable?

java,static

A little bit simpler : public class Count { private static int count = 0; // resets the value to 0 public static void reset() { count = 0; } // updates the value public static String update() { count++; if(count == 1000) count = 1; return String.format("%03d", count); }...

Recursive initialization : Static Initializer not getting called when i access Class field

java,static,classloader

When accessing OOMErrorB.c, OOMErrorB is not loaded because it is already in the process of being loaded (when the JVM initially loaded it in order to invoke the main method). Once a class is loaded in the JVM, it will not be loaded again. Therefore, no cyclic dependency occurs: OOMErrorB's...

Primitive type and reference type objects

c#,static,primitive-types,reference-type

A primitive type is an object which the language has given a predefined value Why? Even references can have predefined values as noted. For primitive (built in) types you may want to say these are types that a language provides built in support for. What your instructor might be...

Passing integer value from MDI parent to child and back

c#,static,mdichild,mdiparent

The proper way of exposing content in OOP is to use properties. you can add a static property on your mdi parent form and use it anywhere in the code: on the MDI form: public static int MyInt {get;set;} inside the button1 click event handler: mdiBK.MyInt = 1; inside the...

nesting classes in Java and referencing them in static main

java,static,nested

You can make Animal class static and make the code work. Or else, If you don't make the inner class(Animal) static. An object of inner class(Animal) can only exists with instance of outer class(Test). So, if you don't want to make it static you will have to create an instance...

access static member of template parent class

c++,templates,inheritance,static

The compiler does not resolve the inherited members for template base classes, due to the fact that you may have specializations that do not define the member, and in that case the whole parsing/name resolving business will become quite difficult. If your member is non-static, then using this->n_parent "assures" the...

Im referencing a constant class static variables, but when i do the values somehow change

c#,visual-studio-2013,reference,static

Your problem is here: public static decimal positivePastLimitDecimal = Convert.ToDecimal(80000000000000E+40) public static decimal negativePastLimitDecimal = Convert.ToDecimal(-8000000000000E-40); You cannot store such big numbers on a decimal. Use float or double for that. The maximum value you can store in a decimal is: 79,228,162,514,264,337,593,543,950,335....

Returning a pointer which is a locally declared wchar_t

c,static,scope,return

It's OK to return a local variable, it's not OK to return a pointer to a local variable. int foo(void) { int var = 42; return var; //OK } int *bar(void) { int var = 42; return &var; //ERROR } In the case of returning a pointer, all it matters...

django static folder name change

python,django,static

You are doing it wrong, see the docs: https://docs.djangoproject.com/en/1.8/howto/static-files/ this is correct way to locate static files: {% static "my_app/myexample.jpg" %} But anyway, you have a misconfigured paths: STATIC_ROOT = os.path.join(BASE_DIR, 'static') ...

How to call static method provided by protocol in Swift

ios,swift,static,protocols

This looks like a bug or a non-supported feature. I would expect that the following works: if let gsType = contact.dynamicType as? GroupStatus.Type { if gsType.isPrivate() { // ... } } However, it does not compile: error: accessing members of protocol type value 'GroupStatus.Type' is unimplemented It does compile with...

Definition of private weak_ptr in template class

c++,templates,static

Just add in the same header: template<class T> std::weak_ptr<T> my_template<T>::wp; Works for me! :)...

C# singleton pattern in a static class?

c#,static,singleton

No, since you can't create instances of a static class there will only be one copy of the field, so there is no need to use the Singleton pattern. Place the construction in the static constructor, which is guaranteed to be called only once, and is thereby automatically thread-safe: https://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx...

std::string vs char array for static const

c++,arrays,static

Yes, yes it does also have to be statically allocated. Always use std::string unless your profiler tells you that it's worth pissing around with legacy crap like const char[]. Choosing const char[] is an annoying micro-optimization over std::string and a stupid decision unless you know for sure that this piece...

Java import static method but not field

java,import,static

You can't. import statements are completely a compile time concept. They don't do anything at run time. They allow you to use the simple name instead of a fully qualified name of types, or their members. When you use import static com.example.ClassName.TEST; you're telling the compiler that you will want...

Why are exceptions in a static constructor wrapped in TypeInitializationException

c#,static

What are the reasons for wrapping the exception in a TypeInitializationException ? Exceptions in static constructors are difficult. Basic issue is that the execution context of the exception is very vague. The CLI does not give any specific promise exactly when the constructor runs. Only guarantee is that it...

django1.8 cannot include css, js files in template

html,css,django,static,django-1.8

I got the media files !!.. I added in settings.py STATICFILES_DIRS = ( os.path.join(BASE_DIR,"static"), '/var/www/test_media/', ) & changed in index.html {% load staticfiles %} <link rel="stylesheet" href="{% static "css/style.css" %}" > <script src="{% static "jquery/jquery.js" %}"></script> ...

Adding subview to static UITableViewCell not working

ios,objective-c,uitableview,static,addsubview

When you have static tableView, you can connect outlets to its cells directly and manipulate like simple subviews. So just connect outlet and use your code to add subviews. It will work UPDATE Add subviews using the following code: [cell addSubview:segment]; ...

static and final static assignment

java,variables,static,variable-assignment,final

The final static fields of primitive and String types are handled specially by java compiler: they are compile time constants. Their value is just inlined into the code where it used. Let's take a look on generated bytecode. Test1 class: static int add(); Code: 0: getstatic #17 // Field a:I...

Laravel Eloquent: access method parameter within chunk Closure

php,laravel,static,scope,eloquent

The use keyword allow the anonymous function to inherit variables from the parent scope. class MyModel extends Eloquent { // ... table stuff public static function doSomething (Closure $thing) { $dispatcher = static::getEventDispatcher(); static::unsetEventDispatcher(); // note the use keyword static::chunk(100, function ($records) use ($thing) { foreach($records as $model) { $thing($model);...

using i686-w64-mingw32-g++ for static libraries

static,jni

-Wl,--export-all-symbols -Wl,--add-stdcall-alias -v adding this solved my problem

OCP Java SE 6 Practice Questions - WeatherTest Enum

java,enums,static,ocp

The code compiles and gives answer C. All that is happening is that your IDE is issuing you with a warning that you should not access static members on an instance of a class, as it it confusing. w.RAINY makes it look like RAINY is an instance field, when in...

Call Javascript function from C# static web method (page method)

javascript,c#,asp.net,static,webmethod

Call the JavaScript function upon successful completion (callback) of the call to the web method in your JS code. You can't "call" client-side code from the code behind; you can register a JS function call as a "startup script" but not here as a call to a web method does...

Thread creation inside constructor

c++,multithreading,static,pthreads

As for your problem, you a pointer to a (non-static) member function is not the same as a pointer to a member function. Non-static member functions needs an instance of an object to be called on. There are a couple of ways to solve this: If you insist on using...

Deploying existing Elastic Beanstalk inside VPC without deleting the RDS associated

amazon-web-services,static,elastic-beanstalk,vpc

In fact for everyone that already has or have the problem. It is quite easy. Create new fresh EC instances (2, maybe 3 to handle traffic). Assign Elastic IPs to that instances. Make a loadbalancer handling the traffic. And then you have a Gateway to work like this : 1)...

Creating a static class with no instances

python,class,object,static

The Pythonic way to create a static class is simply to declare those methods outside of a class (Java uses classes both for objects and for grouping related functions, but Python modules are sufficient for grouping related functions that do not require any object instance). However, if you insist on...

Why cannot I transform the string “Feb 13 23:30:01 2014” to Date in R?

r,string,date,static

As Roland suggested, it's likely a locale issue. Try what's in the Example section of ?strptime. R> lct <- Sys.getlocale("LC_TIME") # store current time locale R> Sys.setlocale("LC_TIME", "C") # Use the "C" time locale [1] "C" R> x <- c("Feb 13 23:28:34 2014","Feb 13 23:30:01 2014","Feb 13 23:32:01 2014", +...

static member variable initializing twice

c++,static,initialization

You could make your factories variable a pointer (initialized to null), and then have your REGISTER_OBJECT macro lazy instantiate it, i.e., set it to new std::map... if it's null.

Why should we use a List of a particular type in Java

java,methods,arraylist,static,format

The <> syntax is called generics - it allows you to limit what type of elements a collection holds, and refer to them by this type. It's not required, it's just more convenient. For instance, you could write the second method without any generics specified, but you'd have to handle...

Static util class with Spring, unsure if I should make it a SpringBean, design concerns

java,spring,spring-mvc,static

Generally, you should favor non-static over static. Regarding your specific example, you should go with Spring beans, because that gives you much more flexibility when you start extending your application/module with more complex features. For example, very soon static-only classes will require some resources from other parts of the system...

Nginx express static files not found

file,express,nginx,static

Finally figured it out. The location block for static files needs to be something like location ~ ^/(assets/|images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) { root /var/www/analytics/web/; access_log off; expires 24h; } ...

How to design a class that is constant after initialization and exists only once in my whole program

c++,design-patterns,static

Singleton is the pattern, but use the safer variant where this approach avoids static initialization order fiasco and thread race conditions and since you complained about the length - we can shorten it a bit further passing the indices through the get_entry function: template <int T> class LookupTable{ public: static...

Change static variable

swift,static,global-variables

If your intent is to make the variable for this instance of ViewController accessible to other classes (i.e. other view controllers), then you don't have to use static. You only need to use static if it is critical to make the property accessible across multiple instances of that class. I...

Using external static library in LPCXpresso

static,libjpeg,lpc

You can easily add a library to Eclipse/LPCXpresso by creating a new project (not a C project or a LPCXpresso project but a 'normal' project) by clicking File->New->Project. Name is as you wish, let's say 'JPEG'. Add your library file to it under the folder 'lib' (you have to create...

Calling base and derived static methods of a type variable

java,generics,static

The reason for this is that the compiler doesn't know which exact subtype of AbstractErrorHandler will be replacing T at Runtime. That's why it just binds the method call T.handle() to the AbstractErrorHandler.handle() method. The problem here is that you're mixing inheritance with the static features of the classes in...

Which is better programming practice - Unnecessary parameters or a static variable?

c#,parameters,constructor,static,xna

For performance it's better to have one static variable and share it between your classes. But usually the performance impact is close to none, unless it's critical code. (By critical code, I mean code that runs a lot of times in one second, e.g. the Update method, or code that...

Another way to program “static”: Is Code ok?

java,static

It's a lot of complication for zero benefit. You can make a singleton instance and throw some inheritance at it, but in the end you cannot whitewash away the fact that you're still calling a static method. Java allows static methods as a way to let you write code that...

Django static files 404 on server, although working locally

python,django,apache,static

You don't have any Alias directives in Apache configuration telling Apache where your static files are and what URL you want them to appear under. See: https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#serving-files ...

Display images on Django Template Site

python,django,image,static

You just need to do: <img src="{{ movie.image_file.url }}" /> User uploaded files go to your MEDIA_ROOT + the upload_to parameter in your model field, which is typically a different location that static files are served from when using the {% static %} template tag. Since your field allows for...

Why can static member functions only be called at global scope if they have a return value?

c++,static,member-function

You cannot call functions at global scope because, from [basic.link] A program consists of one or more translation units (Clause 2) linked together. A translation unit consists of a sequence of declarations. test::dostuff(); is not a declaration - so you cannot have it as a standalone function call (the fact...

C++: static instance of inner class in outer class

c++,static,inner-classes

Since z is a static member variable, it requires a definition. The line of code you are looking at is that definition. X::Z X::z = X::getZ(); X::Z (note the uppercase Z) is the type, X::z (note the lowercase z) is the variable, and it is initialized by the return value...

C: Variable turns to 0 simply calling getline inside for loop

c,variables,for-loop,static,getline

A logical explanation would be that on your platform size_t is bigger than int. If that's the case, your code has UB, and the lv variable gets overwritten when getline updates len. Simply declare len as size_t....