21,185 questions
-5
votes
0
answers
79
views
Reaching constructors in a java static context [closed]
We cannot instantiate an inner class within a static context of the outer class, but when we declare this inner class as package- private. we are able to access its constructor. But how ? what is the ...
-5
votes
3
answers
198
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) : ...
3
votes
6
answers
200
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 ...
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 ...
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 # ...
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:
...
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 ...
2
votes
1
answer
133
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 ?? &...
0
votes
1
answer
77
views
dart issue trying to initialize a Uint8List variable in a named constructor
import 'dart:typed_data';
class Test {
Uint8List testKey;
Test({this.testKey = Uint8List(0)});
}
Gives compile error: Error: Cannot invoke a non-'const' factory where a const expression is ...
3
votes
2
answers
84
views
Substituting template parameter with its known value into a typedef is inconsistent between compilers
The code is not an ideal implementation, but it demonstrates something interesting.
I have a class template with some bool parameters, where specializations of the class have slightly different ...
0
votes
1
answer
146
views
Member "..." is not a typename, Constructor-definition (in .cpp) doesnt take struct as input variable
I'm trying to write some UI-Code (for learning purposes) and I get this error that I can't find a fix to.
The 4 errors are
`E0493` No instance of overloaded function "UIElement::UIElement" ...
1
vote
1
answer
69
views
Why does __init__ requires an explicit self as an argument when calling it as base.__init__()?
I know of two ways to call a superclass's constructor from a derived class: super().__init__() and base.__init__(self). Why does the second require me to explicitly supply self as an argument?
Here's ...
2
votes
3
answers
117
views
Initialization of class array in a template class
I have a class which uses a fixed number of member classes (mInpA, mInpA in my case)
class csAndGate : public csLogicCell
{
public:
csAndGate() :
mInpA(this),
mInpB(this)
{}
...
11
votes
1
answer
203
views
What constructors must be defined to satisfy copy constructible concept for any-like class?
I would like to make a class that satisfies std::copy_constructible concept and in addition can be constructed from an arbitrary copy constructible value much like std::any does:
#include <concepts&...
7
votes
2
answers
208
views
std::tie in constructor's initializer list
I have a following header:
#include <string_view>
#include <tuple>
std::tuple<int, int, int> foo(std::string_view sv);
class s {
public:
s(std::string_view sv);
...
-3
votes
2
answers
81
views
C# Run and wait an async void event in constructor
I'm writing a WPF app and am trying to test its click events quickly. As a first attempt, I called the click events in the constructor. These functions are async void so I wrap them with Task.Run()....
3
votes
1
answer
132
views
Do objects part of a class not get constructed until its constructor is called
For this simple classes below. For MyClass, the constructor initializes str with s during construction using the intializer list.
Does this mean that str doesn't get constructed at all yet until mc ...
-1
votes
1
answer
118
views
Does destructor take care of popping member variables from the stack
Take this very simple class. The main() function just creates an object of it. Even though the constructor and destructor don't have an implementation here. My assumption is that the constructor will ...
1
vote
3
answers
114
views
Calling parameterized constructor only to update one member variable
I have a class with a default constructor which initializes many member variables via initializer lists.
I wish to have a parametrized constructor which only updates one of the member variables. A ...
0
votes
2
answers
40
views
Python subclass constructor calls metaclass with *args and **kwargs
I am trying to instantiate a singleton with constructor argument. However, passing the input arguments to the metaclass hits an error.
from typing_extensions import List, TypedDict, Optional, Any
...
0
votes
0
answers
94
views
Why doesn't cause every thread the constructor to run when the class is initialised with a thread_local?
I have a thread_local variable, which should initialize a class in every thread, but the constructor isn't called, when the threads are opened. The constructor is only called, when I place the ...
-1
votes
5
answers
157
views
Class level instantiation vs constructor or init block [closed]
Probably like many devs, I've picked up practices etc. based on the existing code as well as conversations with colleagues. A question just occurred to me, and I'm not sure if this is a 'best practice'...
2
votes
3
answers
148
views
C++ How to define a member variable that is either passed into or constructed within a constructor
What is a way to define a member object variable of a class that can either be
passed into the constructor (ownership stays external to class) or
constructed inside the class's constructor (ownership ...
0
votes
1
answer
72
views
Passing a constructer as a parameter as if it were a regular function in JavaScript?
I am using ANTLR 4, and it is common to instantiate a class and immediately pass it as the argument of the next class' constructor, as per the docs for the ANTLR 4 JavaScript target:
import antlr4 ...
1
vote
1
answer
85
views
Constructor for Multi-level inheritance in C++
Please see following C++ code:
#include <iostream>
using namespace std;
class alpha
{
int a;
public:
alpha () {};
alpha (int c)
{
a = c;
}
void showalpha (...