21,184 questions
1 vote
0 answers
110 views
What makes QGuiApplication construction hang in this case?
Here's a piece of Qt code: int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QGuiApplication app2(argc, argv); The first constructor call returns, the second does not. I ...
-5 votes
3 answers
205 views
std::shared_ptr const vs non-const, instance vs reference in constructor
Consider passing a shared pointer of const std::shared_ptr<Object> to the ctor of following class. struct MyClass { explicit MyCLass(const std::shared_ptr<const Object> & input) : ...
2 votes
2 answers
111 views
Subtlety in initializing attributes with methods in modules from the `equinox` `jax` library
I have the following code that defines an abstract class and its final subclasse. The two classes are both subclasses of the equinox.Module class, which registers class attributes as the leaves of a ...
3 votes
6 answers
202 views
Generalize a self referential struct construction using a variadic template
I have some tricky code that I need to initialize many objects that refer to each other. I want to allocate and construct them all at once, so I put them all in a struct. It looks like this: // User ...
1 vote
1 answer
93 views
In PHP, should a child class redeclare constructor dependencies if the parent constructor already defines them, or can it omit them entirely?
So I’m kinda stuck wrapping my head around this whole parent-child dependency thing. My assumption was, once you declare all the dependencies in the parent (BaseController), the child (like ...
0 votes
0 answers
34 views
Why Symbols and BigInt can't be instancied using "new" keyword? [duplicate]
While I was learning the language, I became interested in primitive types and their object wrappers. While I was in my code editor discovering this language feature, I discovered that any of these ...
-2 votes
4 answers
142 views
How can I automatically inject common services into all command/query handlers without manually modifying each constructor?
I'm working on a .NET application where every command/query handler needs access to three shared services: IValidator, ISecurity and ILogger. Rather than manually injecting these into each handler ...
4 votes
1 answer
73 views
__new__ function behaves differently after overriding it with setattr
I have the following: class A: def __init__(self, x): self.x = x A(5) # Works fine x = A.__new__ # Save the function A.__new__ = lambda y: y # Temporarily override it A.__new__ = x # ...
1 vote
2 answers
115 views
Creating virtual object in constructor initialization
I want to create a variable of type Foo. The class Foo consists of a variable called Bar bar_ which is filled directly in the constructor initialization. The thing is, class Bar has a reference to the ...
6 votes
1 answer
246 views
Why can my C++ class be implicitly converted in one case, but not another?
I'm getting a compiler error about a type conversion that should be legal, to my eyes. Let's say I have a home-grown string class, convertible from and to char*: class custom_string { public: ...
1 vote
1 answer
88 views
PHP calling model function
I'm trying to learn constructors and statics and I'm not sure what I'm doing wrong here controller <?php namespace App\Http\Controllers\Api; use App\Models\SampleModel; class SampleController { ...
2 votes
1 answer
48 views
x class is not a constructor [closed]
My error is SiteChecker is not a function I was following this guy steps https://www.thepolyglotdeveloper.com/2020/06/scan-broken-links-website-javascript/ to set up package and execute , but on my ...
0 votes
1 answer
122 views
How to explicitly instantiate forwarding constructor in C++?
I'm trying to explicitly instantiate a forwarding constructor using C++20 with GCC 13.3 compiler in order not to put its definition in the header file. Here is a minimal example: Foo.h #pragma once ...
2 votes
1 answer
135 views
Why is a field not initialized when using a custom record copy constructor?
I have this record: record Foo { string _bar = "initialized"; public string Bar => _bar; } I'm running the following code: var foo = new Foo(); Console.WriteLine(foo?.Bar ?? &...
1 vote
1 answer
62 views
SML pattern matching on datatypes with constructors from function arguments
In the example, there is a "match redundant" Error, indicating that SOME s is matching on every string and not the provided s: fun matchs (s : string) : (string option -> bool) = fn x =&...