static

Is it legal C++ to pass the address of a static const int with no definition to a template?

I'm having trouble deciding whether not this code should compile or if just both compilers I tried have a bug (GCC 4.2 and Sun Studio 12). In general, if you have a static class member you declare in a header file you are required to define it in some source file. However, an exception is made in the standard for static const integrals. ...

When do I use static variables/functions in php?

I am refreshing myself on OOP with PHP and I saw an example of setting functions and/or variables as static. When and why would I set a variable/function to static? I've done other languages and don't really recall ever using static, I never found a real purpose to it. I know what it does but why not just use a variable instead? ...

_beginthreadex static member function

How do I create a thread routine of a static member function class Blah { static void WINAPI Start(); }; // .. // ... // .... hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL); This gives me the following error: ***error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void (void)' to 'unsigne...

Why is a const variable available within a static method?

I have been writing code without realizing WHY I can access constant values within static methods. Why is it possible to access const values without declaring it as static? E.g.) It's legal to call IMAGE_FILE_EXTENSION within AddImageToDocument(...) public abstract class ImageDocumentReplacer : DocumentReplacer { private const ...

C# : So if a static class is bad practice for storing global state info, what's a good alternative that offers the same convenience?

Hi, I've been noticing static classes getting a lot of bad rep on SO in regards to being used to store global information. (And global variables being scorned upon in general) I'd just like to know what a good alternative is for my example below... I'm developing a WPF app, and many views of the data retrieved from my db are filtered b...

PHP static variables in double quotes

Hi, How can I get PHP to evaluate a static variable in double quotes? I want to do something like this: log("self::$CLASS $METHOD entering"); I've tried all sorts of {} combos to get the variable value of self::$CLASS, but nothing has worked. I've currently settled with string concatenation but it is a pain to type: log(self::$CLA...

Are function static variables thread-safe in GCC ?

In the example code void foo() { static Bar b; ... } compiled with GCC is it guaranteed that b will be created and initialized in a thread-safe manner ? In gcc's man page, found the -fno-threadsafe-statics command line option: Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initiali...

Liferay - Serve static content

Hi, How can I serve some static content in liferay? I have a directory structure with htmls, css, etc and I would like to serve it with an address like http://localhost:8080/myStaticContent/index.html and so on. I don't want to use a front-end http server like apache. ...

C++: When (and how) are C++ Global Static Constructors Called?

Hi, I'm working on some C++ code and I've run into a question which has been nagging me for a while... Assuming I'm compiling with GCC on a Linux host for an ELF target, where are global static constructors and destructors called? I've heard there's a function _init in crtbegin.o, and a function _fini in crtend.o. Are these called by c...

c# What is the different between static class and non-static (I am talking about the class itself not the field)

The syntax maybe wrong public static class Storage { public static string filePath { get; set; } } And public class Storage { private void Storage () {}; public static string filePath { get; set; } } I got this from an example on the internet. what is the use of the second o...

Classes and file reading

Can an object of ifstream type used for file reading be a static member of a class? I want to read a file and store each line in an array of objects of a class i have created. I want the file reading object to belong to the entire array of objects instead of one single instance of the class. ...

Getting static property from a class with dynamic class name in PHP

Hi Guys, I have this: one string variable which holds the class name ($classname) one string variable with holds the property name ($propertyname) I want to get that property from that class, the problem is, the property is static and I don't know how to do that. If the property weren't static, it would have been: $classname->$pro...

Circular C++ Header Includes

In a project I have 2 classes: // mainw.h #include "IFr.h" ... class mainw { public: static IFr ifr; static CSize=100; ... }; // IFr.h #include "mainw.h" ... class IFr { public float[mainw::CSize]; }; But I cannot compile this code, getting an error at the static IFr ifr; line. Is this kind of cross-inclusion prohibited? ...

Lua scripting implementation

Hello, I'm currently working on implementing Lua into one of the applications that I'm working on. Currently I'm just using the C api and registering functions using lua_register, but I'd like to be able to pass static and non static function pointers to certain class methods. I've found certain libraries on the net, but since I need...

How to initialize unmanaged static pointer in C++/CLI code?

Hi all, thanks for checking my problem:) I'm not able to initialize a static native pointer inside a managed class. Here's the detail: I created a C++/CLI console project and declared a static unmanaged pointer inside. However I can't initialize the static pointer with any means (but if I put the pointer into an anonymous namespace, th...

Extern and Static Pointers in C

Hi what could be the usage of static and extern pointer ?? if they exist ...

C# - Execute a static method in a new process

Hi All, I wanted a help in executing a static method asynchronously as well as in it's own process so that even if the client application that kicked-off this execution is closed, the method will continue it's execution. One option to do this is create a console application and execute this console application as a new process. However...

How to statically link to the CRT with GCC?

Using GCC4 in MAC OSX, Linux and Windows. Thanks. ...

Dependency injection with a static logger, static helper class

Hi I have a static class which calls a static Logger class, e.g static class DoesStuffStatic { public static void DoStuff() { try { //something } catch(Exception e) { //do stuff; Logger.Log(e); } } } static class Logger { public static void Log(Exception e) { //do stuff here ...

Why should we use static calls in PHP?

Why should we use static variables or static calls to static methods in PHP5? Maybe to improve performance? ...