constructor Questions
4
Solved
I have a class with the constructor:
...
Date d1;
Date d2;
public DateClass(Date d1, Date d2) {
this.d1 = d1;
this.d2 = d2;
}
...
Then in another class I want to use this constructor:
...
Dat...
Eke asked 10/12, 2011 at 20:51
4
Solved
I have this simple record in Java:
public record DatePair( LocalDate start , LocalDate end , long days ) {}
I want all three properties (start, end, & days) to be available publicly for readin...
Proffitt asked 5/8, 2023 at 21:2
6
Solved
I have a base class Character which has several classes deriving from it. The base class has various fields and methods.
All of my derived classes use the same base class constructor, but if I don...
Basidiomycete asked 28/11, 2010 at 13:9
1
Consider the following example that compiles with clang but is rejected by edg, gcc and msvc. Demo
#include <initializer_list>
struct C
{
C(){}
C(std::initializer_list<int> i = {3})...
Kizzie asked 5/8 at 21:8
1
Solved
I learned that when a class has a user-provided constructor then the compiler will not implicitly generate a default constructor. I wrote the following code, C d{}; in particular, and I expect it t...
Eyeopener asked 5/8 at 20:0
2
Solved
I recently learnt that constructors do not have names. I am also aware that a function has a type called a function type. For example,
void func(int)
{
}
In the above snippet, func has the functio...
Rime asked 3/4, 2022 at 9:59
4
Solved
I am trying to build a "type", for the Timecode convention used in Film/Animation.
I want to accommodate use cases where a user may want to initialise the object with a Timecode string go...
Recusancy asked 5/9, 2023 at 19:30
5
Solved
I'm working in Java and have come across an incredibly odd error. I have a very basic class as follows:
public class ClassA{
private static Logger log = Logger.getLogger(ClassA.class.getName());
...
Telltale asked 26/9, 2012 at 15:5
5
Solved
I know that in C# you can nowadays do:
var a = new MyObject
{
Property1 = 1,
Property2 = 2
};
Is there something like that in PHP too? Or should I just do it through a constructor or through m...
Largish asked 1/10, 2010 at 9:26
4
Solved
In the new MVC Core it seems the standard way to get the context to the controller is by doing this
public class BaseController : Controller
{
public readonly ReportDBContext _db;
public BaseCo...
Mayle asked 16/6, 2020 at 14:53
3
Solved
I have this example:
#include <iostream>
#define print(X) std::cout << X << std::endl
struct B1 {
B1(int _i = 5): i(_i) { print("B1 constructor"); };
int i;
};
struc...
Hemicrania asked 10/7 at 7:43
5
Solved
Why does the main Spring Boot application always trigger PMD's HideUtilityClassConstructorCheck?
The standard Spring Boot application has some main method class file, say SampleApplication.java, that looks like this:
@SpringBootApplication
@RestController
public class SampleApplication {
pu...
Hypophosphite asked 13/5, 2016 at 21:17
4
I am not so happy with primary constructors - because the constructor parameters are not readonly, it's too error prone in my opinion, especially when working with base classes which receive their ...
Incurrence asked 24/1 at 11:39
8
Solved
Actually I can not understand that what is the difference between a no-arg constructor and a default constructor.
import javax.swing.*;
public class Test extends JFrame {
public Test() {
super(...
Router asked 26/12, 2014 at 7:29
6
I'm trying to make a ajax request to upload a image. My problem is when I create the FormData. My console is saying "dataForm is not a constructor".
How can I solve this ?
here is my script
$("...
Laudian asked 27/5, 2016 at 17:35
1
When examining the constructors of std::tuple on the cppreference site, I came across the move constructor defined below, which is available in C++23.
template< class... UTypes >
constexpr tu...
Hadrian asked 5/5 at 13:42
5
Solved
New to Ruby, and I'm trying to figure out what idiom to use to restrict some integer values to the constructor of a class.
From what I've done so far, if I raise an exception in initialize(), the ...
Codie asked 28/9, 2009 at 2:12
7
Solved
Imagine I have a C++ class Foo and a class Bar which has to be created with a constructor in which a Foo pointer is passed, and this pointer is meant to remain immutable in the Bar instance lifecyc...
Jemappes asked 14/9, 2009 at 20:22
7
My question is what does a constructor return? This question is not quite different from "What is the return type of a constructor?"
I have read somewhere that a constructor returns a complete obje...
Chibcha asked 23/11, 2010 at 4:6
7
Solved
I want to make a stub to prevent time.sleep(..) to sleep to improve the unit test execution time.
What I have is:
import time as orgtime
class time(orgtime):
'''Stub for time.'''
_sleep_speed_...
Steal asked 3/4, 2014 at 11:53
1
Solved
#include <iostream>
#include <thread>
template<int Num>
class MyClass {
public:
MyClass(int val) : val_(val) {}
// Copy constructor
MyClass(const MyClass& other) : val_(o...
Rase asked 26/4 at 8:35
12
Solved
This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest's execution order). Both the method marked [TestInitialize] and the test class constructor wil...
Dichromate asked 2/12, 2008 at 16:15
5
Solved
We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package.
Within the package there are a set of classes that are all va...
Expressman asked 31/10, 2017 at 6:39
7
Solved
Can we make a class copy constructor virtual in C++? How to use?
Educative asked 27/3, 2012 at 12:24
25
Solved
I need to create a Set with initial values.
Set<String> h = new HashSet<String>();
h.add("a");
h.add("b");
Is there a way to do this in one line of code? For instance, it's useful fo...
Laevorotatory asked 11/1, 2010 at 12:31
1 Next >
© 2022 - 2024 — McMap. All rights reserved.