I'm trying to figure out why this example doesn't compile. My understanding is that if a static variable is not explicitly set then it defaults to 0. In the five examples below four of them behave as I would expect, but the one that's commented out won't compile.
#include <iostream>
class Foo
{
public:
static int i;
static int ...
I asked a question earlier today about singletons, and I'm having some difficulties understanding some errors I encountered. I have the following code:
Timing.h
class Timing {
public:
static Timing *GetInstance();
private:
Timing();
static Timing *_singleInstance;
};
Timing.cpp
#include "Timing.h"
static Timing *Timi...
Ok... in C++ you can new up a subclass from a static method in the base class with 'new this()' because in a static method, 'this' refers to the class, not the instance. That was a pretty damn cool find when I first found it and I've used it often.
However, in C# that doesn't work. Damn!
So... anyone know how I can 'new' up a subclass...
Hi!
I wonder if there is the "nicer" way of initialising a static vector than below?
class Foo
{
static std::vector<int> MyVector;
Foo()
{
if (MyVector.empty())
{
MyVector.push_back(4);
MyVector.push_back(17);
MyVector.push_back(20);
}
}
}
It's an example code...
I am currently investigating a performance issue in an application and have highlighted the following;
I have a class -
public static class CommonIcons
{
...
public static readonly System.Windows.Media.ImageSource Attributes = typeof(CommonIcons).Assembly.GetImageFromResourcePath("Resources/attributes.png");
...
}
As a te...
I am developing an Android app and I am using a library I wrote. This library has a class that contains some static fields. One of them is a API key. This key is used by other classes in my library to make calls on a remote service.
I initialize the API key on my main Activity once when it is created and the savedInstanceState is null.
...
Hi,
My website uses a web user control. The properties for the user control will be set will be common for a set of my users. e.g. if I have 20 users accessing my website, 5 of them may be using the user control with id = 1 , 4 using the user control with id =2. I have a property associated with each user control which I would like to b...
Given the files:
// file: q7a.h
static int err_code = 3;
void printErrCode ();
///////////// END OF FILE /////////////////
// file: q7a.c
#include <stdio.h>
#include "q7a.h"
void printErrCode ()
{
printf ("%d ", err_code);
}
///////////// END OF FILE /////////////////
// file: q7main.c
#include "q7a.h"
int main()
{
err_code = 5;
printEr...
I had a C++ interview recently where I was asked, how does the compiler differentiate static data members having the same name in two different classes?
Since all static data variables are stored in the data segment, there has to be a way by which the compiler keeps track of which static data belongs to which class especially when they...
I have Class A which is super class for both class B and class C. I need to store the objects of Class A in 'static' NSMutablearray defined in Class A. Is it possible to modify data stored in MSMutableArray using methods in Class B and Class C? How to create and initialize Static array? An example would be of more help. thanks in advance...
Hi
I am trying out my first program in Ada of creating a single player dice game.
But facing problem in maintaining score of the player.
Goal: Each player has 10 turns and scores 10 points if total of 2 rolls is 7
Problem: Every time total score gets reset and 10 does not get added to current score.
Total_Score is the final score to be ...
I know that is a beginner's question. I'm new to java and and also to programming in general.
Say I got a class that has only static data, example:
class Foo {
private static int x; }
I want to use the class without instantiating any object. So I want to be able to do:
Foo.setX(5);
Foo.getX();
What is the best way to implement th...
I am trying to understand what this means, the code I am looking at has
in .h
typedef void (*MCB)();
static MCB m_process;
in .C
MCB Modes::m_process = NULL;
And sometimes when I do
m_process();
I get segmentations fault, it's probably because the memory was freed, how can I debug when it gets freed?
I hope my questions ar...
In order to improve speed of chat application, I am remembering last message id in static variable (actually, Dictionary).
Howeever, it seems that every thread has own copy, because users do not get updated on production (single server environment).
private static Dictionary<long, MemoryChatRoom> _chatRooms = new Dictionary<long, Memor...