All Questions
Tagged with inheritance constructor
1,567
questions
2
votes
1
answer
85
views
How to return smart pointers and covariance in C++
I am following this tutorial to understand how to return smart pointers and covariance in C++.
#include <memory>
#include <iostream>
class cloneable
{
public:
virtual ~...
3
votes
1
answer
48
views
Multiple constructors annotated with Lombok @Builder cause a problem?
This is my first question, so please feel free to correct anything that I missed writing this question:)
I am having trouble with using the @Bulider with my DTO objects.
I have an abstract class "...
-2
votes
0
answers
55
views
a constructer declared in a type with parametere list must have 'this' constructor inisializer error [closed]
I'm working on a C# project where I have an abstract base class Employee with a parameterized constructor Employee(string name). My derived class FullTimeEmployee has a constructor that takes three ...
5
votes
3
answers
170
views
Initialization order of inherited constructors
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;
};
...
-1
votes
0
answers
56
views
Compiler misidentifying/unrecognising type [duplicate]
I have the following class with constructor:
command.h:
#include "./robots.h"
enum class CMD { //...... };
class CommandTemplate {
//.....
public:
virtual std::unique_ptr<...
1
vote
1
answer
49
views
Constructor parameter is null until parent is not initialized
Look at the following code:
abstract class A {
init {
f()
}
abstract fun f()
}
class B(val p: () -> Unit) : A() {
override fun f() {
try {
p()
...
-1
votes
2
answers
102
views
C# Initialize inherited record form base record
I have a base record type and an inherited record type which adds a few fields.
At runtime I have an instance of the base record type and want to convert it to an instance of the inherited record type,...
1
vote
0
answers
19
views
Constructor-chaining, order of parameters?
You know you can chain constructor calls:
class A
{
function constructor()
{
}
}
class B extends A
{
function constructor()
{
parent.constructor();
}
}
but there can ...
-1
votes
1
answer
48
views
Inheritance in Java and its confusing things [closed]
class A {
public void m() {
System.out.println("A.m");
}
public void n() {
System.out.println("A.n");
}
}
class B extends A {
@Override
...
1
vote
2
answers
83
views
Is it allowed to pass "this" of derived class to constructor of base class?
Here is the code I originally wanted to write:
class A {
public:
A(someType someData) {
this->init(someData);
}
virtual void init(someType) = 0;
}
This is not allowed, ...
-1
votes
2
answers
107
views
Inheritance - is it possible to 'force' variable values relative to the derived class?
I am trying to create a simple model. A vehicle can only ever have 1 VehicleType, and a VehicleType is a Vehicle. As such I have created a base class Vehicle, and three derived classes Bike, Car, and ...
0
votes
0
answers
58
views
Why is base constructor available via curly braces but not via parentheses? [duplicate]
I've come across the following issue. Here is a simple piece of code:
struct Base {
Base(int x) : x_{x} {}
int get() { return x_; }
private:
int x_ = 0;
};
struct Derived : Base {};
int main(...
0
votes
0
answers
62
views
Initialize a struct with a const default through copy
I was trying to define a AbstractOptions struct that would hold some options that are used later on for a different class Operator with a concrete implementation ImplementedOptions. As a default value ...
-1
votes
1
answer
54
views
Bunch of errors that aren't valid, probably because of formatting but I can't crack it
public class TicketTest
{
int serial;
public static void main(String args[])
{
int total_sales = 0;
new WebTicket(10);
new WebTicket(5);
...
0
votes
2
answers
83
views
Create object of subclass by object of superclass [python]
there is way (in python) to create subclass obj by superclass obj?
I have to parse a file so I have to:
open file and parse => superclass obj
try to extend file if conditions are good => ...