constructor Questions

4

I'm trying to embrace C# 8's nullable references types in my project and make it smoothly work with EF Core. Following this guide, I made my entity classes have constructors accepting all data nee...

8

Solved

I've heard about this happening in non thread-safe code due to improperly constructed objects but I really don't have the concept down, even after reading about in in Goetz's book. I'd like to soli...
Nonmoral asked 19/10, 2009 at 12:30

5

Solved

I can get the ID of the authenticated user like this: Auth::user()->id = $id; Great it works, ... but I have a load of methods which need it and I want a cleaner way of adding it to the clas...
Husch asked 22/6, 2015 at 21:59

0

I can declare a C# positional record like this: public record Box(double Capacity); which results in the definition of a record class named Box with a property named Capacity, as well as a primary...
Hulahula asked 31/3, 2024 at 13:56

1

Solved

It is not very rare to find a library that zeros its objects in the constructors using memset. And sometimes it happens to empty classes as well. Is it safe, especially when one inherits such class...

7

Solved

Are constructors allowed to throw exceptions?
Outdoor asked 3/9, 2009 at 3:58

3

I have a Python class that issues a warning inside __init__(). It also provides a factory class method for opening and reading a file: from warnings import warn class MyWarning(Warning): """Warn...
Smectic asked 28/1, 2019 at 10:0

7

I'm just a beginner in Python and programming in general, and have some questions about the unittest module. I have a class, and in the __init__ method I am doing some assertions to check for bad...
Chubby asked 15/6, 2009 at 17:10

2

Solved

I am dealing with stop the constructor. public function __construct() { $q = explode("?",$_SERVER['REQUEST_URI']); $this->page = $q[0]; if (isset($q[1])) $this->querystring = '?'.$q[1];...
Suave asked 2/1, 2015 at 12:54

14

How do I create a private constructor which should be called only by the static function of the class and not from else where?
Disheveled asked 21/11, 2011 at 12:48

14

Solved

Is there a way to have some kind of default constructor (like a C++ one) for C user types defined with a structure? I already have a macro which works like a fast initializer (like the one for pth...
Aubine asked 11/2, 2009 at 15:11

13

Solved

#include <iostream> using namespace std; class T1 { const int t = 100; public: T1() { cout << "T1 constructor: " << t << endl; } }; When I am trying to i...
Pigweed asked 24/1, 2013 at 6:53

7

Solved

I am writing an application that requires me to take a proprietary bitmap format (an MVTec Halcon HImage) and convert it into a System.Drawing.Bitmap in C#. The only proprietary functions given to...
Fermentative asked 2/2, 2010 at 16:56

18

Solved

It's weird that this is the first time I've bumped into this problem, but: How do you define a constructor in a C# interface? Edit Some people wanted an example (it's a free time project, so yes,...
Volitive asked 6/3, 2009 at 18:13

1

Solved

From the C++ standard working draft: Default constructors ([class.default.ctor]), copy constructors, move constructors ([class.copy.ctor]), copy assignment operators, move assignment operators ([c...

5

Solved

How can I declare a class type, so that I ensure the object is a constructor of a general class? In the following example, I want to know which type should I give to AnimalClass so that it could ...
Victual asked 21/9, 2016 at 10:43

5

I was wondering, why I cannot call a constructor. Even this small example fails to compile with the message: Klassentest.cpp:24:27: error: cannot call constructor 'Sampleclass::Sampleclass' direc...
Neri asked 4/12, 2015 at 9:41

17

Solved

I have a project where I'm trying to populate some data in a constructor: public class ViewModel { public ObservableCollection<TData> Data { get; set; } async public ViewModel() { Data ...
Monadism asked 16/11, 2011 at 1:19

15

Solved

Summary: I would like to call an asynchronous method in a constructor. Is this possible? Details: I have a method called getwritings() that parses JSON data. Everything works fine if I just call g...
Confluence asked 13/4, 2014 at 20:49

6

Solved

I have a class which has not default constructor. And I need a way to get 'blank' instance of this class. 'blank' means that after instantiation all class fields should has default values like null...

7

I split up my class constructor by letting it call multiple functions, like this: class Wizard: def __init__(self, argv): self.parse_arguments(argv) self.wave_wand() # declaration omitted def...
Malenamalet asked 10/10, 2013 at 0:4

6

Solved

Suppose I have the following (simplified case): class Color; class IColor { public: virtual Color getValue(const float u, const float v) const = 0; }; class Color : public IColor { public: fl...
Plainsong asked 28/9, 2009 at 14:8

2

Solved

I created the following class: export class MyItem { public name: string; public surname: string; public category: string; public address: string; constructor(); constructor(name:string, su...

10

Solved

Can I call constructor explicitly, without using new, if I already have a memory for object? class Object1{ char *str; public: Object1(char*str1){ str=strdup(str1); puts("ctor"); puts(str); ...
Rachaba asked 22/3, 2010 at 17:44

2

Solved

I recently came across some weird looking class that had three constructors: class Class { public: explicit Class(int ); Class(AnotherClass ); explicit Class(YetAnotherClass, AnotherClass );...
Ree asked 13/7, 2009 at 10:20

© 2022 - 2025 — McMap. All rights reserved.