I have a base class A with a constant static variable a. I need that instances of class B have a different value for the static variable a. How could this be achieved, preferably with static initialization ?
class A {
public:
static const int a;
};
const int A::a = 1;
class B : public A {
// ???
// How to set *a* to a valu...
I know that the static objects in .Net managed world are loaded in Loader Heap which is never going to be garbage collected.
What happens to the instance reference parameters passed to a static methods. Are they get garbage collected once the static function executed completely Or they are going to live forever as those instance referen...
What are the key uses of a Static Generic Class in C#? When should they be used? What examples best illustrate their usage?
e.g.
public static class Example<T>
{
public static ...
}
Since you can't define extension methods in them they appear to be somewhat limited in their utility. Web references on the topic are scarce so cl...
Say I have a class:
public class R {
public static final int _1st = 0x334455;
}
How can I get the value of the field/property "_1st" via reflection?
...
First of all, I read erickson's useful reply to "Why can’t I define a static method in a Java interface?". This question is not about the "why" but about the "how then?".
Edit: my original example was ill-posed, but I'll leave it bellow.
While I am now convinced that in most cases what I want to do is overkill, there is one scenario wh...
If I have a static class with a static field such as:
private static myField = new myObject();
I then have a bunch of static methods that use myField.
Is myField re-instantiated for each method call? My guess is that it's instantiated the first time a method is called that uses it and it remains in memory until the GC clears it up?
...
How does the following work?
#include <limits>
int main()
{
const int* const foo = &std::numeric_limits<int> ::digits;
}
I was under the impression that in order to take an address of a static const-ant member we had to physically define it in some translation unit in order to please the linker. That said, after looking at the prep...
If I create an instance of a class in Java, why is it preferable to call a static method of that same class statically, rather than using this.method()?
I get a warning from Eclipse when I try to call static method staticMethod() from within the custom class's constructor via this.staticMethod().
public MyClass() { this.staticMethod();...
Today I dediced to make static linking in Qt. I used Qt4 with Visual Studio and static C runtime article. The 3rd step took quite a long time. When it was finished I opened my project in VS 2008, made Build->Clean Solution and try to Release. Unfortunately I got link errors:
warning
LNK4098: defaultlib 'libcmt.lib'
conflicts with...
I'm trying to create a class which contains a static pointer to an instance of itself. Here's an example:
A.h:
#include <iostream>
#ifndef _A_H
#define _A_H
class A {
static A * a;
};
A * a = NULL;
#endif
However, when I include A.h in another file, such as:
#include "A.h"
class B {
};
I get the following error:
ld: dupli...
I have certain documents that I want to limit access to through Django to authorized users with permissions only.
If I'm going to use Django as a proxy to serve static files in a view, what are the implications? I'm used to serving static files in Apache and configuring that my media is served without any handlers, but what happens if s...
I have Python classes, of which I need only one instance at runtime, so it would be sufficient to have the attributes only once per class and not per instance. If there would be more than one instance (what won't happen), all instance should have the same configuration. I wonder which of the following options would be better or more "idi...
Given what I know of every other type of static feature of programming––I would think the answer is 'no'. However, seeing statements like OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass(); makes me wonder.
...
Hi all,
I've got a strange problem with a static variable that is obviously not initialized as it should be.
I have a huge project that runs with Windows and Linux. As the Linux developer doesn't have this problem I would suggest that this is some kind of wired Visual Studio stuff.
Header file
class MyClass
{
// some other stuff he...
So ive got a base class which requires a Socket:
class Sock
{
public Socket s;
public Sock(Socket s)
{
this.s = s;
}
public virtual void Process(byte[] data) { }
...
}
then ive got another class. if a new socket gets accepted a new instance of this class will be created:
class Game : Sock
{
publi...
In C++ is not possible to declare a static virtual function, neither cast a non-static function to a C style function pointer.
Now, I have a plain ol' C SDK that uses function pointers heavily.
I have to fill a structure with several function pointers. I was planning to use an abstract class with a bunch of static pure virtual method...
Why does the following code return 100 100 1 1 1 and not 100 1 1 1 1 ?
public class Hotel {
private int roomNr;
public Hotel(int roomNr) {
this.roomNr = roomNr;
}
public int getRoomNr() {
return this.roomNr;
}
static Hotel doStuff(Hotel hotel) {
hotel = new Hotel(1);
return hotel;
}
public static void main(String arg...
I am having difficulty with the following code which is inside a static method of a non-static class.
int iRand;
int rand;
rand = new Random((int)DateTime.Now.Ticks);
iRand = rand.Next(50000);
The iRand number, along with some other values, are being inserted into a new row of an Access MDB table via OLEDB. The iRand number is being...
Are the following equivalent?
private static boolean readAllFiles = false,readAllDirs = false;
private static boolean readAllFiles = false;
private static boolean readAllDirs = false;
And if so, do they still have the same modifiers with different values?
private static boolean readAllFiles = false,readAllDirs = true;
...
Hi, I'm having the same problem as this guy with the application I'm writing right now. The problem is that static properties are not being inherited in subclasses, and so if I use the static:: keyword in my main class, it sets the variable in my main class as well.
It works if I redeclare the static variables in my subclass, but I expe...