702 questions
2
votes
1
answer
77
views
Why doesn’t Xcode show documentation for class initializers when creating an object in Swift?
I’m working with Swift and I’ve documented my class initializers using ///.
However, when I create an object with let obj = MyClass(...), the documentation does not appear when I Option-Click the ...
12
votes
7
answers
2k
views
Construct an std::array at compile time in C++17 using the preprocessor
I am developing a C++17 framework that has optional third-party dependencies and I'd like to construct an std::array that contains the names of the available dependencies.
The CMake file sets ...
1
vote
1
answer
49
views
AspectJ staticInitialization changes the method context on the code in the clinit when doing @Around
This question is a follow up to the question here
AspectJ @around a static initializer
I accepted that answer because it did apply the aspect to the code, but i hadn't actually run it yet to see there ...
0
votes
1
answer
66
views
AspectJ @around a static initializer
I'm attempting to use a point cut of
@Around("staticinitialization(*)")
but when applying i get this error:
[iajc] [error 4]: error at /home/dave/dev/coyote/projects/aspects/debug_src/com/...
0
votes
1
answer
100
views
Inexplicable C++ error message: too many initializers [closed]
I am compliling a C++ file (on a Raspberry Pi5 running Debian 12 with Gnu C++) and the file is auto-generated from a XML datafile. The file just has some const arrays of structs. One of the arrays ...
0
votes
0
answers
32
views
Get Initializer result from Hilt module
Simple question here: is it possible to get an object initilized through app startup Initializer inside a Hilt module?
Let me provide an example. Assume that I've the following Initializer:
class ...
2
votes
2
answers
123
views
Correct syntax for whole array initializaition
Why is the following an error and what is the correct syntax?
struct a {
int b[4];
};
int c[4];
struct a a = {.b = &c};
Shouldn't a.b be of type int * or int[], why is it of type int?
(Note, ...
0
votes
0
answers
61
views
Terminating app due to uncaught exception 'Attempt to call unavailable initializer
I have a view controller with a button. Once clicked, a new view controller is suppose to be presented.
CropperViewController
@IBAction func cropImageAction(_ sender: AnyObject) {
...
3
votes
2
answers
144
views
C array padding
I have many data array defined in my code with the length only specified in the array initializer.
int a[] = {1, 2, 3, 4};
int b[] = {1, 2, 3, 4, 5};
For cache line coherence consideration, I want to ...
0
votes
1
answer
139
views
Correct way to write a @model in swiftdata
I'm working on a Swift project where I have two model classes: PlaylistGroup and PlaylistItem. I'm running into an issue where I can't append items to the playlistItems property in PlaylistGroup. ...
1
vote
1
answer
238
views
Convert optional substring to string in Swift
Apple's documentation and many articles suggest you can convert a substring (string.subsequence) to a string just by calling String(substring)and in fact this works.
let str = "Hello world"
...
3
votes
1
answer
224
views
variable conditionally declared constexpr according to its initialization expression
I'd like to be able to conditionally declare a variable constexpr, according to properties of its initializer.
My actual use case is a bit complicated but it can be summarized to:
#include <cmath&...
1
vote
1
answer
98
views
Passing a constructor initialized value to another method
I want to use the local db "isar" in flutter together with cubit state management. In the following code:
The variable "isarIn" is initialized in the main() method
Then passed to ...
3
votes
1
answer
85
views
Confusion about type deduction in variadic templates
I have a class with multiple constructors, one being variadic and one taking an additional callable before the variadic arguments. However, the objects I create result in overload resolutions I dont ...
0
votes
2
answers
122
views
Initialize List<T> with index--is this a bug?
In C# you can initialize Dictionary<TKey,TValue> like this:
var dictionary = new Dictionary<int, string>()
{
[0] = "Hello",
[1] = "World"
};
You can also ...
0
votes
1
answer
39
views
How to make a custom kernel (or bias) weights initializer which makes -1 or 1 values randomly for Keras Dense?
In pure Python I can make it easily:
from random import choice
def init_by_plus_or_menus() -> int:
return choice([-1, 1])
Keras documentation uses in the example Keras.backend (tf) function:
...
3
votes
1
answer
120
views
How could be an initializer expression is "assignment-expression" by the grammer?
I have this sample of code:
struct S {};
S s = S();
Per my understanding, I see that s = S() in the declaration S s = S() is an init-declarator where s is a declarator and = S() is an initializer.
...
-4
votes
1
answer
205
views
'Initializer element is not a compile-time constant' when assigning a variable [closed]
I'm trying to run this code but on the terminal it says 'initializer element is not a compile-time constant:
#include <cs50.h>
#include <stdio.h>
int main(void)
int i = get_int ('first ...
1
vote
1
answer
59
views
Is it possible to create a custom function initializer?
Sorry if this has already been answered, but I haven't been able to find the answer myself.
I was wondering if it is possible to create a custom function initializer? Something like this:
const ...
1
vote
1
answer
84
views
Failable initializer with Result type?
I have a struct MyStruct. It can be initialized from a String, but there are many ways for the String to be invalid. Rather than simply creating a failable initializer init?(string: String) which ...
-1
votes
1
answer
487
views
Error message: expected initializer before 'switch' [closed]
#include <iostream>
using namespace std;
int main()
switch(age)
{
case 1:
case 2:
case 3:
case 4:
cout<< "Tricycle"<<endl;
break;
case 5:
.
.
case 15:
if (15 >= age >...
1
vote
0
answers
102
views
C++ compile error using initializer list on map<string, string>
Given this class which takes a map as a constructor parameter
struct Map
{
Map(const map<string, string>& map)
{
}
};
And this sample code to create it
string s;
Map j({ {s, s}})...
-1
votes
1
answer
604
views
SwiftUI: Pass binding to object initializer inside of init function
In my App i want to initialize an @StateObject property that takes a binding in its initializer. I created an example project to try fixing this problem.
struct ContentView: View {
@StateObject ...
0
votes
2
answers
48
views
Created a Date Selection View in SwiftUI and having an error with No exact matches in call to initializer
I used a ForEach to present the calender. I am missing something in my code and can't place my finger on it. Any help is needed. This is the error: No exact matches in call to initializer
import ...
1
vote
1
answer
98
views
Can a C initializer keep data grouped inside a AoSoA struct?
If we start from AoS layout, AoS structs can be easily initialized as such:
struct Position { float x; float y; };
struct Position positions[] = {
{ .x = 1.f, .y = 2.f },
{ .x = 20.f, .y = ...
-1
votes
1
answer
163
views
Why do memberwise initializers become 'private' when the structure contains a private property?
The default memberwise initializer for a structure type is considered private if any of the structure’s stored properties are private.
(Source: https://docs.swift.org/swift-book/documentation/the-...
1
vote
2
answers
477
views
What is "initializer" in android studio?
I have a program from official android tutorials about creating a database. The program has lots of viewmodels which I guess are instantiated in viewModelFactory. But what does the keyword "...
0
votes
1
answer
90
views
Start a timer when Object is created
I like a timer to start when an object is created. (see code below in playground).
My problem is the timer seem to never start.
How can I start a timer when a Object is created?
import Foundation
...
0
votes
1
answer
92
views
Collection initializer doesn't work with collection definition
I tried merging a collection definition with a collection initializer in C#, but failed to initialize the collection. See the codes:
using System.Collections;
using System.Collections.Generic;
using ...
0
votes
1
answer
257
views
In solidity, what's the need of verifying 'address(this)' is a contract?
In openzeppelin's Initializable.sol library(v4.7.0), there is a modifier initializer() that checks if a function has already been initialized. In the require statement, it checks the value of ...
0
votes
1
answer
142
views
'(callback function) can`t be accessed in an initializer' Error
I am studying flutter while making a pomodoro app.
After setting this app to 25 minutes, press the middle button to decrease the time by seconds and press the button again to pause.
I am getting the ...
0
votes
1
answer
60
views
Is a "named" static initializer valid Java? [closed]
I've only ever heard of a static initializers with the syntax "static {...}".
But in this book, Core Java by Cay Horstmann, there's some code like this: (private static Holder {...})
12.4....
2
votes
2
answers
170
views
Workaround for data member initialization happening after base class construction
I would have liked to do something like this:
template<typename T>
class RasterView {
T* data;
unsigned stride;
RasterView(T* data, unsigned stride)
: data(data)
, ...
1
vote
0
answers
193
views
Struct initialization changes in C++ 20 [duplicate]
#include <memory>
struct Something
{
int x;
long y;
};
int main()
{
std::unique_ptr<Something> k = std::make_unique<Something>(0, 1);
return 0;
}
This program ...
0
votes
0
answers
126
views
G++ aborts compilation with no error message when file contains large array initializer
I'm using Code::Blocks (v20.03) with MinGW64 g++ compiler (Windows 11), g++ --version shows (first line):
g++.exe (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 12.2.0
When trying to ...
0
votes
1
answer
362
views
How to initialize bias with a pre-defined vector in tensorflow [duplicate]
How can I initialize bias with a pre-defined vector (no constant or random)? For example, I would like to spread up the vector in the range [-1, 1]. Something likee this:
tf.linspace(-1, 1 , shape, ...
0
votes
2
answers
146
views
SwiftUI - share dictionary among views, unclear what arguments to use at @Main / WindowGroup
I'm trying to build an app (macOS, but would be the same for iOS) that creates a number of grids, the outcome of which is to be shown in a second screen. For this, I'm sharing data across these ...
3
votes
1
answer
399
views
Does the default argument for a function parameter is considered as an initializer for that parameter?
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-clause ...
4
votes
1
answer
149
views
Create a LINQ expression in F# for C# object initializer
I am using a .NET framework which allows to pass an object initializer LINQ expression when called from C#:
db.UpdateAdd( () => new InvoiceAccount { Quantity = 3 } );
The framework uses the ...
1
vote
1
answer
159
views
In C, is there a way to make struct initialization of subobjects not initialize to zero?
Say I have a struct with an array inside it:
struct my_struct {
// 128 will be enough for all of my use cases,
// saves me from using malloc.
double values[128];
int value_count;
...
-2
votes
1
answer
140
views
Instance Initializer Exception Handling
I didn't understand the difference between these codes. One of them is compiled, the other one isn't.
{
if (true) {
try {
throw new IOException();
} catch (IOException ...
0
votes
1
answer
201
views
Why can't structure initialization work with array of char?
When initializing a struct using curly braces, it does not seem to work with an array of chars. I can write an equivalent constructor that works below. Is there any syntax so I don't have to write the ...
0
votes
1
answer
527
views
Dart creating constructor without this keyword
I could not get the constructor logic with the below code block. In the named constructors we use ClassName({this.variable or required this.variable}); But, in the below example the developer choose a ...
0
votes
3
answers
87
views
How C++ call parameterized ctor to create object arrays?
I know in c++11 I can use initializer to create array/vector elements one by one like:
int ar[10]={1,2,3,4,5,6};
vector<int> vi = {1,2,3,4};
This is done manually, but what if I wish to ...
0
votes
1
answer
82
views
Apparently undocumented GCC behaviour with "constant" initializers in C
Consider the following C code:
#include <stdio.h>
int x = 5;
int y = x-x+10;
int z = x*0+5;
int main()
{
printf("%d\n", y);
printf("%d\n", z);
return 0;
}
The ANSI ...
0
votes
1
answer
133
views
Can C# Collection Initializers accept a lambda generator or only fixed values
This is kind of a duplicate of c#, using lambdas with collection initialization, but its 13 odd years old and things have changed. Hopefully.
I'm writing a one off unit test, so I'm not looking for ...
1
vote
2
answers
135
views
why doesn't GCC place a statically-initialized C++ class object into .data
here are two similar declarations of an object type in C++:
struct Obj {
int x;
};
struct ObjC {
int x;
ObjC(int x) : x(x) {};
};
Obj obj1 = {100}
ObjC obj2(200);
using a recent version ...
0
votes
1
answer
29
views
Initializer doesn't create instance in console
I am new to ruby and I am trying to create a hangman game, to do so I need to create a new game each time the user click on a button.
First step is to create the same object each time the methode ...
0
votes
1
answer
38
views
Why is there an argument although I don't give an argument?
I am new to ruby and I am trying to create a hangman game, to do so I need to create a new game each time the user click on a button.
First step is to create the same object each time the methode ...
1
vote
2
answers
786
views
Stripe API key missing in controller
I am trying to setup Stripe checkout as described in this GoRails episode
I have defined the publishable_key and secret_key in application.yml using the figaro gem so in my config/initializers/stripe....