initializer Questions

2

I have a program with way too many static initializers and destructors. I want to get rid of all of them. So i need a way to find them. Running nm on the executable gives something like this: 0004...
Mastectomy asked 5/2, 2011 at 2:3

3

Solved

I want to set a class attribute when my Rails app starts up. It requires inspecting some routes, so the routes need to be loaded before my custom code runs. I am having trouble finding a reliable p...

5

Solved

What is the recommended way to declare a struct that contains an array, and then create a zero-initialized instance? Here is the struct: #[derive(Default)] struct Histogram { sum: u32, bins: [...
Rajiv asked 21/11, 2014 at 13:49

10

Solved

I have an helper class with some static functions. All the functions in the class require a ‘heavy’ initialization function to run once (as if it were a constructor). Is there a good practice for ...
Sarraceniaceous asked 22/7, 2010 at 19:49

2

Solved

I'd like to automatically run some code upon class creation that can call other class methods. I have not found a way of doing so from within the class declaration itself and end up creating a @cla...
Leralerch asked 24/8, 2012 at 19:13

3

Solved

I have an assignment that requires me to understand what are designated initializers in C, and what it means to initialize a variable with one. I am not familiar with the term and couldn't find any...
Conch asked 9/11, 2017 at 13:3

4

Solved

It is common to use {0} to initialize a struct or an array but consider the case when the first field isn't a scalar type. If the first field of struct Person is another struct or array, then this ...
Frowsty asked 11/7, 2013 at 9:15

23

Solved

I want to have a class with a private static data member: class C { // read-only, can also be static const // should be filled with all characters from 'a' to 'z' static std::vector<cha...
Noway asked 28/7, 2009 at 22:26

2

Solved

I have the following code (EDIT: Updated the code so everyone can compile it and see): import UIKit struct Action { let text: String let handler: (() -> Void)? } class AlertView : UIView { ...
Faeroese asked 26/2, 2018 at 20:4

1

Suppose I have function declarations like these: static const int R = 0; static const int I = 0; void f(const int& r = R); void g(int i = I); Per [dcl.fct.default]/1: If an initializer-claus...
Yellowgreen asked 21/9, 2022 at 12:53

4

Solved

I have a protocol LoginStrategy public protocol LoginStrategy { func login(_ viewController: UIViewController) func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [St...
Basia asked 29/11, 2016 at 6:28

3

Solved

The code: import SwiftUI public struct Snackbar<Content>: View where Content: View { private var content: Content // Works OK public init(@ViewBuilder content: () -> Content) { self.c...
Workmanship asked 7/3, 2022 at 14:57

0

Why am I getting this error? In one of the Dense layers I want to specify the HE Uniform weight initializer, like so: Dense(64, input_shape=input_shape, kernel_initializer=tf.keras.initializers.he_...
Smokejumper asked 11/11, 2021 at 11:51

7

Solved

I tried to make a program that separates characters. The question is: "Create a char array and use an array initializer to initialize the array with the characters in the string 'Hi there'. Disp...
Pleven asked 24/1, 2013 at 10:2

10

Solved

So I've been brushing up on my Java skills as of late and have found a few bits of functionality that I didn't know about previously. Static and Instance Initializers are two such techniques. My q...

1

Solved

When compiling this code in latest verson of gcc (or clang) with -std=c17 -pedantic-errors -Wall -Wextra static const int y = 1; static int x = y; then I get no compiler diagnostic message even th...
Profiterole asked 5/7, 2021 at 8:0

1

Solved

Sometimes in Swift, it may be convenient to write an initializer for a class which delegates to JSONDecoder or a factory method. For example, one might want to write final class Test: Codable { le...
Certificate asked 1/6, 2021 at 0:26

3

Solved

I've some warnings while trying to compile program in C language: 13:20: warning: excess elements in array initializer [enabled by default] 13:20: warning: (near initialization for ‘litera’) [en...
Schapira asked 25/11, 2012 at 9:54

4

Solved

I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically, it'd look like this: public static f...
Reproduction asked 8/12, 2009 at 12:50

3

Solved

For my surprise, using the CreateDatabaseIfNotExists context initializer, the line context.Database.Initialize(true) doesn't throw an exception if the schema does not match my code first schema....
Gratuity asked 26/10, 2012 at 15:2

2

I'm trying to set length and initialize a vector member of a class, but it seems it's only possible if initializing line is out of class. //a vector, out of class set size to 5. initialized each va...
Polychasium asked 10/11, 2016 at 23:39

4

Solved

I simply want to create an array of two dimensional arrays to store coordinate points. So I want an array where each index returns a two dimensional array which I would use as x and y. Here's wha...
Epizootic asked 18/1, 2016 at 9:41

2

Solved

Consider this code: void foo() { goto bar; int x = 0; bar: ; } GCC and Clang reject it, because the jump to bar: bypasses variable initialization. MSVC doesn't complain at all (except using x...

2

Solved

When I create a new subclass of UITextView in the Xcode 6 Beta, the following code is automatically provided. import UIKit class TerminalView: UITextView { init(frame: CGRect) { super.init(fra...
Ceylon asked 6/6, 2014 at 5:42

1

Can you please explain the following object instantiation ? How it is called ? Where can I find more information about this kind of object instantiation ? #include <string> #include <iost...
Edna asked 6/1, 2020 at 21:41

© 2022 - 2024 — McMap. All rights reserved.