initialization

How can you access XAML-set properties of a UserControl during initialization?

你。 提交于 2020-01-22 12:42:45
问题 We're writing a custom UserControl (as opposed to a lookless control) and we need to perform some initialization based on what properties our consumers set on our control in XAML. Now in most cases, you'd use the Initialized event (or the OnInitialized override) since by the time that fires, all the XAML-set properties have been applied, but in the case of a UserControl, that isn't the case. When the Initialized event fires, all properties are still at their default values. I didn't notice

How can you access XAML-set properties of a UserControl during initialization?

北慕城南 提交于 2020-01-22 12:42:10
问题 We're writing a custom UserControl (as opposed to a lookless control) and we need to perform some initialization based on what properties our consumers set on our control in XAML. Now in most cases, you'd use the Initialized event (or the OnInitialized override) since by the time that fires, all the XAML-set properties have been applied, but in the case of a UserControl, that isn't the case. When the Initialized event fires, all properties are still at their default values. I didn't notice

Different ways of initializing an object in c++

◇◆丶佛笑我妖孽 提交于 2020-01-22 08:04:32
问题 I'm pretty sure this is a duplicate question, but I've been searching for a while and I didn't get any smarter. Imagine this class: class Entity { public: int x, y; Entity() : x(0), y(0) { } Entity(int x, int y) : x(x), y(y) { } } And here are multiple ways of initializing the class: Entity ent1; Entity ent2(); Entity ent3(1, 2); Entity ent4 = Entity(); Entity ent5 = Entity(2, 3); I also know that's it's possible make an object on the heap memory, but that's not a great mystery to me at this

Different ways of initializing an object in c++

為{幸葍}努か 提交于 2020-01-22 08:03:27
问题 I'm pretty sure this is a duplicate question, but I've been searching for a while and I didn't get any smarter. Imagine this class: class Entity { public: int x, y; Entity() : x(0), y(0) { } Entity(int x, int y) : x(x), y(y) { } } And here are multiple ways of initializing the class: Entity ent1; Entity ent2(); Entity ent3(1, 2); Entity ent4 = Entity(); Entity ent5 = Entity(2, 3); I also know that's it's possible make an object on the heap memory, but that's not a great mystery to me at this

Different ways of initializing an object in c++

痞子三分冷 提交于 2020-01-22 08:02:59
问题 I'm pretty sure this is a duplicate question, but I've been searching for a while and I didn't get any smarter. Imagine this class: class Entity { public: int x, y; Entity() : x(0), y(0) { } Entity(int x, int y) : x(x), y(y) { } } And here are multiple ways of initializing the class: Entity ent1; Entity ent2(); Entity ent3(1, 2); Entity ent4 = Entity(); Entity ent5 = Entity(2, 3); I also know that's it's possible make an object on the heap memory, but that's not a great mystery to me at this

How to initialize an array in one step using Ruby?

限于喜欢 提交于 2020-01-22 04:22:07
问题 I initialize an array this way: array = Array.new array << '1' << '2' << '3' Is it possible to do that in one step? If so, how? 回答1: You can use an array literal: array = [ '1', '2', '3' ] You can also use a range: array = ('1'..'3').to_a # parentheses are required # or array = *('1'..'3') # parentheses not required, but included for clarity For arrays of whitespace-delimited strings, you can use Percent String syntax: array = %w[ 1 2 3 ] You can also pass a block to Array.new to determine

Initiating a class from string with extra step?

a 夏天 提交于 2020-01-21 19:41:09
问题 I've been looking into substantiating a new class instance from a string in PHP. This is seems to be an acceptable procedure, however I am curious why it can't be done with the returns of a function call. I posted a short test below, and my results indicate it works if there is a variable intermediary (i.e. $bar = new $foo->callBar(); does not work, while $x = $foo->callBar(); $bar = new $x; does). class Foo { function callBar() { return 'Bar'; } } class Bar { function sayHi() { echo 'Hi'; }

Initialization of val by destructuring in Kotlin

半城伤御伤魂 提交于 2020-01-21 19:01:44
问题 Initially I wanted to achieve class NotationDiceRoll(notation: String) { val rolls: Int val sides: Int init { parseNotation(notation) } private fun parseNotation(notation: String) { rolls = 1 sides = 4 } } But Kotlin complains that "Val cannot be reassigned". It seems that the only place where the vals can be assigned is the init block. Alright then, it is more obvious after all. So I changed it to class NotationDiceRoll(notation: String) { val rolls: Int val sides: Int init { (rolls, sides)

Accessing lambda capture initialized variable outside the lambda in C++

寵の児 提交于 2020-01-21 11:51:06
问题 In C++14/17, how do you access a lambda capture initialized variable outside the scope of the lambda? Source: #include <iostream> using namespace std; int main(){ auto test = [value1 =0]() mutable {value1+=1; return value1;}; cout << test() << endl; cout << test() << endl; //cout << value1 << endl;//error: ‘value1’ was not declared in this scope } Output: 1 2 Is the value1 variable accessible outside the scope of the test() lambda? What is the lifetime of a lambda capture initialized variable

Initializing a dynamically-sized Variable-Length Array (VLA) to 0

牧云@^-^@ 提交于 2020-01-21 07:14:07
问题 The following line of code, which creates a variable-length array on the stack: char name[length] = {'\0'}; Generates the following compiler diagnostics: error: variable-sized object may not be initialized warning: excess elements in array initializer warning: (near initialization for ‘name’) What options are available to me for initializing VLAs? Am I forced to use a line such as: memset(name, 0, sizeof(name)); Instead? 回答1: Yes, you must write code for the initialisation of VLAs (which