static-members

struct static member meaning/definition [closed]

本秂侑毒 提交于 2019-12-30 07:46:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . struct a{static int z;}l; (a is declared at file scope) I cant initialize the z using a initializer list. what does a static struct member mean? does z(name) have external linkage and public access as well? (I thought it meant you give it file scope and group it under a(and has public access through a object)?.

Java: Overriding static variable of parent class?

戏子无情 提交于 2019-12-29 07:23:09
问题 I have the following class which I'm using as the base of all the models in my project: public abstract class BaseModel { static String table; static String idField = "id"; public static boolean exists(long id) throws Exception { Db db = Util.getDb(); Query q = db.query(); q.select( idField ).whereLong(idField, id).limit(1).get(table); return q.hasResults(); } //snip.. } I'm then trying to extend from it, in the following way: public class User extends BaseModel { static String table = "user"

c++ template singleton static pointer initialization in header file

左心房为你撑大大i 提交于 2019-12-28 07:01:09
问题 What is wrong with this implementation in header file? template <typename T> class Singleton { public: static T* getInstance() { if (m_instance == NULL) { m_instance = new T(); } return m_instance; } private: static T* m_instance; }; I use it like this: typedef Singleton<MyClass> MyClassSingleton; I get linker error: error LNK2001: unresolved external symbol "private: static class MyClass * Singleton<class MyClass>::m_instance" (?m_instance@?$Singleton@VMyClass@@@@0PAVMyClass@@A) When I add

C++ member-function pointer

岁酱吖の 提交于 2019-12-28 04:32:21
问题 Consider the following class class Foo { typedef bool (*filter_function)(Tree* node, std::list<std::string>& arg); void filter(int filter, std::list<std::string>& args) { ... if (filter & FILTER_BY_EVENTS) { do_filter(events_filter, args, false, filter & FILTER_NEGATION); } ... } void do_filter(filter_function ff, std::list<std::string>& arg, bool mark = false, bool negation = false, Tree* root = NULL) { ... } bool events_filter(Tree* node, std::list<std::string>& arg) { ... } }; I can pass

Why is a class allowed to have a static member of itself, but not a non-static member?

大兔子大兔子 提交于 2019-12-28 03:01:27
问题 class base { public: base a; }; It gives compilation error. class base { public: static base a; }; whereas this code does not give compilation error 回答1: Because static class members are not stored in the class instance, that's why a static would work. Storing an object inside another object of the same type would break the runtime - infinite size, right? What would sizeof return? The size of the object needs to be known by the compiler, but since it contains an object of the same type, it

is it possible to define the static member function of a class in .cpp file instead of its header file?

霸气de小男生 提交于 2019-12-25 17:05:37
问题 i am having a function which should be run only once for all instance of the class.i thought to use the static function calling method. all the web example shows that static function define in the Header file(inside the class) itself. my function is big one i cant define that in header file what should i do? for that. 回答1: Like you do for normal functions: FooBar.h #ifndef FOOBAR_H #define FOOBAR_H class FooBar { public: static void test(); }; #endif FooBar.cpp #include "FooBar.h" void FooBar

Pass Non-Static Member without externally setting it

耗尽温柔 提交于 2019-12-25 04:54:13
问题 I have two classes defined as: class Control { private: std::vector<int> Info; public: Control(..); virtual ~Control(); LRESULT __stdcall SubClass(HWND Window, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData); }; class Button: public Control { //... }; Control::Control(..) { SetWindowSubclass(..., SubClass, ...); //Need to pass member function as callback.. } LRESULT __stdcall Control::SubClass(HWND Window, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR

Pass Non-Static Member without externally setting it

心不动则不痛 提交于 2019-12-25 04:54:06
问题 I have two classes defined as: class Control { private: std::vector<int> Info; public: Control(..); virtual ~Control(); LRESULT __stdcall SubClass(HWND Window, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData); }; class Button: public Control { //... }; Control::Control(..) { SetWindowSubclass(..., SubClass, ...); //Need to pass member function as callback.. } LRESULT __stdcall Control::SubClass(HWND Window, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR

Initializing private member static const array

て烟熏妆下的殇ゞ 提交于 2019-12-25 04:45:25
问题 class MyClass { public: ... private: enum class BDTNodeType : unsigned char { NT_TERMINAL_ZERO, NT_TERMINAL_ONE, NT_TERMINAL_X, NT_NOT_TERMINAL }; class BDTNode { public: explicit BDTNode(BDTNodeType node_type = BDTNodeType::NT_NOT_TERMINAL); BDTNode(const BDTNode &node); ~BDTNode(); BDTNodeType type; BDTNode *thenPtr; //1 BDTNode *elsePtr; //0 }; BDTNode *root_node; //Constant nodes static const BDTNode fv_nodes[3] = { BDTNode(BDTNodeType::NT_TERMINAL_ZERO), BDTNode(BDTNodeType::NT_TERMINAL

Lifetime of static class members/class references? [duplicate]

蓝咒 提交于 2019-12-25 02:43:08
问题 This question already has an answer here : Can a simple difference in Python3 variable names alter the way code runs? [duplicate] (1 answer) Closed 5 years ago . I was asked to show how to do a singleton like solution for the old chestnut of a special logger. At pains to point out the reasons for not doing this sort of thing, still, I tried. In doing so, I have a static class member disappearing unexpectedly. With this class declaration: epiLogger.py: import logging class epiLogger():