I'm new to Java, so I'm sure this is an easy question (my head is spinning from studying all day long). Here's the code I'm studying and can't remember/figure out what this line of code is doing:
public Temperature(String type, double degrees) {
if (type.equalsIgnoreCase("C"))
Is this considered a constructor? What are the two parameters "Stri
it1352
2
2019-05-14
Please tell me why the constructor does not return any value. I want a perfect technical reason to explain to my students why the constructor does not have any return type.
Solution What actually happens with the constructor is that the runtime uses type data generated by the compiler to determine how much space is needed to store an object instan
it1352
0
2019-05-14
i have the following
class sequence {
public:
sequence (const sequence& mysequence, const int newjob) {
job_sequence(mysequence.job_sequence)
job_sequence.push_back(newjob);
...
}
vector<int> job_sequence;
}
what i want is: if i have a sequence object, i want to be able to create a
new object that copies the job_sequence within it and
it1352
2
2019-06-25
I have a doubt that I cannot solve. I have read the documentation at embarcadero for class constructors but I cannot understand the meaning of that. In other words, what is the usage difference between a constructor and a class constructor? I did this:
type
TGeneric<T> = class
private
FValue: T;
aboutString: string;
procedure s
it1352
3
2019-05-15
Do we have to explicitly define a default constructor when we define a copy constructor for a class?? Please give reasons.
eg:
class A
{
int i;
public:
A(A& a)
{
i = a.i; //Ok this is corrected....
}
A() { } //Is this required if we write the above copy constructor??
};
it1352
1
2019-05-10
I have a constructor
private Double mA;
private Double mB;
Foo(Double a) {
mA = a;
mB = a 10;
}
Foo(Double a, Double b) {
mA = a;
mB = b;
// some logic here
}
if I make a call to second constructor like this:
Foo(Double a) {
Double b = a 10;
this(a, b);
}
than compiler tells me, that constructor should be the first statem
it1352
0
2019-05-22
It's possible that someone has already asked about this but googling for "default", "defaulted", "explicit" and so on doesn't give good results. But anyway.
I already know there are some differences between an explicitly defined default construtor (i.e. without arguments) and an explicitly defined defaulted constructor (i.e. with the keyword defau
it1352
0
2020-10-08
Before continue reading this, please read Is there a difference in C between copy initialization and assignment initialization? first, make sure you understand what it is talking about.
I'll summarize the rule here first (read standard n3225 8.5/16, 13.3.1.3, 13.3.1.4, and 13.3.1.5),
1) For direct initialization, all constructors will be consid
it1352
2
2019-05-14
For example, I want to declare a class but I want the client to not be able to use the copy constructor (or copy assignment operator)
Both of the following two does not allow the use of the copy constructor:
1.
class Track
{
public:
Track(){};
~Track(){};
private:
Track(const Track&){};
};
2.
class Track
{
public:
Track(){};
~Tr
it1352
0
2019-05-10
As a C# developer I'm used to run through constructors:
class Test {
public Test() {
DoSomething();
}
public Test(int count) : this() {
DoSomethingWithCount(count);
}
public Test(int count, string name) : this(count) {
DoSomethingWithName(name);
}
}
Is there a way to do this in C ?
I tried ca
it1352
0
2019-05-10