static-members

Modern way to create static or Class variable for Javascript class

被刻印的时光 ゝ 提交于 2019-12-07 00:26:40
问题 I've been hunting around for a clear answer to this, and most of what pops up still relates to the old (or should I say "traditional") way of defining classes using function . According to this SO answer, Class properties are not supported in ES2015. As far as I can tell, the only way to add a static variable to a class is like: https://jsfiddle.net/abalter/fknwx3n4/ class C { constructor(x) { console.log("in constructor " + x); this.x = x; this.add(this.x); } add(x) { console.log("in add " +

Why must non-integral static data members initialized in the class be constexpr?

主宰稳场 提交于 2019-12-06 18:33:28
问题 Static integral data members initialized in the class definition may be declared const or constexpr , but non-integral static data members initialized in the class definition must be constexpr : class MyClass { static const int w = 5; // okay static constexpr int x = 5; // okay static const float y = 1.5; // error! static constexpr float z = 1.5; // okay }; Does anybody know why the declaration for y is not permitted? The part of the Standard making it illegal is 9.4.2/3, but why is it

Class-scoped enum

廉价感情. 提交于 2019-12-06 17:44:03
问题 I have a c++ class with an enum inside, and I wanted to mimick that with boost::python , so that I can write MyClass.value in python. boost::python::class_ does not have an enum_ method, and I was looking for workarounds. I first tried with lambdas like MyClass{ enum{value1,value2}; }; class_<MyClass>("MyClass").add_property("value1",&[](){return value1;}).staticmethod("value1"); which gives compiler error (in get_signature for add_property ). I know I could create getter method for each of

Proper initialization of static constexpr array in class template?

不问归期 提交于 2019-12-06 17:21:52
问题 Static class members in C++ have caused a little confusion for me due to the standard's verbiage: 9.4.2 Static data members [class.static.data] The declaration of a static data member in its class definition is not a definition... However a constexpr is required to be initialized (AFAIK, couldn't find a quote from the standard) at its declaration (e.g., in the class definition). Because of the restrictions on constexpr I had actually forgotten about the requisite for static members to be

why this weird order of constructor/static initializer/static member function in java?

半腔热情 提交于 2019-12-06 11:42:31
public class DataFactory { private static DataFactory ourInstance = new DataFactory(); static { System.out.println("static initialize"); } private DataFactory() { System.out.println("constructor"); } public static void doNothing() { System.out.println("inside doNothing"); } } public class App { public static void main(String[] args) { System.out.println("main start"); DataFactory.doNothing(); } And After I run it, here is the printed sequence: main start constructor static initialize inside doNothing Why calling DataFactory.doNothing() will trigger Constructor? and why constructor is running

Static member error in c++

送分小仙女□ 提交于 2019-12-06 11:32:32
I am trying to define a static member pointer in C++. However I get a linker error. The error is 1>main.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A) 1>Solution.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A) Code: class Solution{ public: Activity **solution; Solution(); Solution(Activity **list, bool direction); static Activity** temp; }; Activity is another class. How can I solve this problem? You have to add the

Is it possible to load/read shape_predictor_68_face_landmarks.dat at compile time?

血红的双手。 提交于 2019-12-06 09:44:56
问题 I am trying to build a C++ application in Visual Studio using DLIB's face_landmark_detection_ex.cpp. The build application run from command promt and trained model and image file is passed as arguments. face_landmark_detection_ex.exe shape_predictor_68_face_landmarks.dat image.jpg this shape_predictor_68_face_landmarks.dat is the trained model for 68 landmarks to perform detection on input image and needs to load at run-time every time to perform any detection. I am trying to do following

Static field initialization in template class in C++

瘦欲@ 提交于 2019-12-06 03:28:48
问题 I'm trying to create some self-registering classes in C++. So I tried the solution similar to the one provided here. While doing this I stumble over something strange. Here's the code: #include <iostream> class StaticClassType { public: StaticClassType() { // Notify when the static member is created std::cout << "We're in." << std::endl; } }; template<typename T> class TestClass1 { public: TestClass1() { &m; } private: // Static member in a template class static StaticClassType m; }; template

two instances of a static member, how could that be?

六眼飞鱼酱① 提交于 2019-12-06 00:44:50
问题 I have a multithreaded application. I declare a class with a static member in a shared library. Printing the address of the member from different threads from different libraries shows different results. //declaration template <class OBJECT> struct Container { static int m_member; }; template <class OBJECT> int Container<OBJECT>::m_member; // printing cout << (void*) &Container<int>::m_member << endl; How could that be? 回答1: If you have different libraries, (I'm guessing different dynamic

Android Application life cycle and singelton

北慕城南 提交于 2019-12-05 13:04:59
well most of us familiar with this pattern: public class MySingeltone { public String mSomeReferenceTypeData; public int mSomeValueTypeData; private static MySingeltone mInstance; private MySingeltone() { } public static MySingeltone getInstance() { if (mInstance == null) { mInstance = new MySingeltone(); } return mInstance; } } my problem is that I've found recently that the mInstance don't equal null after activity using him been destroyed, or when the whole application suppose to be clause, for example: public class SomeActivity extends Activity { @Override protected void onCreate(Bundle