initialization

C# explicit initialization for Enum

你说的曾经没有我的故事 提交于 2020-06-28 10:19:11
问题 I have the following statement: private Enum _statusValue; What I'd really like to say is: private Enum _statusValue = 0; even though I know it's redundant. It's just that I like to explicitly specify the initialization. But that is not allowed. Is there some simple way of specifying the initialization on this kind of declaration? EDIT - Let me try again. Here is a contrived / simplified example of what I'm doing. using System; namespace EnumTesting { public enum EFixedPhoneUsability {

Creating a static global, variable length 2D array

此生再无相见时 提交于 2020-06-24 17:02:11
问题 I am trying to create an array with the following requirements: internal linkage (static global) size only known at runtime elements accessed using the [][] syntax stored on the heap I have been using the following code to create a VLA which meets almost of my requirements, but this array is limited to the current scope rather than having internal linkage. int (*array_name)[columns] = malloc( sizeof(int[rows][columns]) ); Is there any way to create an array which meets all of my needs? Edit -

Creating a static global, variable length 2D array

无人久伴 提交于 2020-06-24 17:01:58
问题 I am trying to create an array with the following requirements: internal linkage (static global) size only known at runtime elements accessed using the [][] syntax stored on the heap I have been using the following code to create a VLA which meets almost of my requirements, but this array is limited to the current scope rather than having internal linkage. int (*array_name)[columns] = malloc( sizeof(int[rows][columns]) ); Is there any way to create an array which meets all of my needs? Edit -

create SKScene subclasses programmatically, without size info?

落花浮王杯 提交于 2020-06-22 12:05:22
问题 I'm trying to learn how to make a GameManager type class, and making individual classes for each of my GameScenes... probably the wrong thing to do, but for the sake of this question, please accept this as the way to do things. My GameManager looks like this, having a reference to each of the scenes, that's static: import SpriteKit class GM { static let scene2 = SecondScene() static let scene3 = ThirdScene() static let home = SKScene(fileNamed: "GameScene") } How do I create a SKScene

Initialize an Associative Array with Key Names but Empty Values

旧城冷巷雨未停 提交于 2020-06-22 09:26:06
问题 I cannot find any examples, in books or on the web, describing how one would properly initialize an associative array by name only (with empty values) - unless, of course, this IS the proper way(?) It just feels as though there is another more efficient way to do this: config.php class config { public static $database = array ( 'dbdriver' => '', 'dbhost' => '', 'dbname' => '', 'dbuser' => '', 'dbpass' => '' ); } // Is this the right way to initialize an Associative Array with blank values? //

make_unique with brace initialization

不羁的心 提交于 2020-06-13 19:08:57
问题 https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique writes that std::make_unique can be implemented as template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } This does not work for plain structs with no constructors. Those can be brace-initialized but don't have a non-default constructor. Example: #include <memory> struct point { int x, z; }; int main() { std::make_unique<point>(1, 2)

make_unique with brace initialization

半世苍凉 提交于 2020-06-13 19:07:33
问题 https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique writes that std::make_unique can be implemented as template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); } This does not work for plain structs with no constructors. Those can be brace-initialized but don't have a non-default constructor. Example: #include <memory> struct point { int x, z; }; int main() { std::make_unique<point>(1, 2)

Initializing Arrays in C/C++ With Unknown Size [closed]

孤街浪徒 提交于 2020-06-10 15:11:17
问题 Closed. This question does not meet Stack Overflow guidelines. 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 . How can I initialize an array in C such as void initArr(int size) { ... } The C language does not give the option to initialize an array if his size is not an constant value, and if I initialize it generally (int *arr;) so it gives me error of 'arr' is not being initialized. Similarily

Why it is allowed to initialize static variable with non const here?

纵饮孤独 提交于 2020-06-08 05:57:29
问题 I was reading this. The first answer by @Andrei T says that A "large" object is never a constant expression in C, even if the object is declared as const. Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type. For example, this is NOT a constant const int N = 5; /* `N` is not a constant in C */ The above N would be a constant in C++, but it is not a constant in C.

Why it is allowed to initialize static variable with non const here?

倾然丶 夕夏残阳落幕 提交于 2020-06-08 05:57:11
问题 I was reading this. The first answer by @Andrei T says that A "large" object is never a constant expression in C, even if the object is declared as const. Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type. For example, this is NOT a constant const int N = 5; /* `N` is not a constant in C */ The above N would be a constant in C++, but it is not a constant in C.