constructor

Base Constructor Call in Derived Class

戏子无情 提交于 2019-12-20 05:35:15
问题 I have got the following problem in a homework for university, the task is as follows: Derive a class MyThickHorizontalLine from MyLine . One requirement is that the constructor of the derived class MyThickHorizontalLine does not set the values itself, instead its obligated to call the base constructor. Which currently looks like this in my cpp file: MyThickHorizontalLine::MyThickHorizontalLine(int a, int b, int c) { MyLine(a, b, c, b); } This is my Base constructor: MyLine::MyLine(int x1,

Why is the value of the instance field coming null?

扶醉桌前 提交于 2019-12-20 05:14:47
问题 I have this simple piece of code. abstract class X { X() { read(); } private void read() { Object obj = new Object(); readValue(obj); } protected abstract void readValue(Object obj); } class Y extends X { Object obj = null; Y() { super(); } @Override protected void readValue(Object obj) { this.obj = obj; } void printer() { System.out.println("Object = " + obj); } } class Runner { public static void main(String[] args) { Y y = new Y(); y.printer(); } } When I run the above code, the object

Difference between constructor in ES6 class and constructor in prototype?

六眼飞鱼酱① 提交于 2019-12-20 04:58:07
问题 Both ES6 class and prototype of function have a contructor , but I'm wondering are they the same? Let me give more explanations. So, I create a Cat function, for instance: const Cat = function (name) { this.name = name; }; The Cat has the following prototype: This constructor can be lost if I type smth. like Cat.prototype = {}; , but new Cat('Name'); will continue working. Ang we have the following syntax in ES6: class Dog { constructor(name) { this.name = name; } } The class also has

Call of overloaded constructor is ambiguous

时光怂恿深爱的人放手 提交于 2019-12-20 04:55:18
问题 I am trying to implement an object-oriented binary tree, however, I get the error message of a call of an overloaded constructor being ambiguous. The problem is that I really do have the necessary constructor, yet C++ doesn't seem to recognize it. My code: http://pastebin.com/PM9PDYAN The error message: 56 36 In constructor 'Node::Node(const int&, Node*, Node*, const int&)': 56 36 [Error] call of overloaded 'Node(const int&, Node* const)' is ambiguous 17 3 [Note] Node::Node(const int&, Node*)

Interface does not have constructor, then how can it be inherited?

扶醉桌前 提交于 2019-12-20 04:29:07
问题 As I know the subclass constructor calls the super class constructor by using super(); . But since interface doesn't have any constructor, how can inheritance take place? 回答1: But since interface doesn't have any constructor how can inheritance take place?? Easy, an interface cannot have any instance fields so there is nothing to construct. You cannot place in code in an interface (up to Java 7 anyway) so there is nothing which needs to be called. 回答2: The interface is a contract, defining

Constructor cannot call itself c#

空扰寡人 提交于 2019-12-20 03:57:08
问题 Constructor "Delay.vkMessages.vkMessages(string, System.DateTime, string, bool, string)" cannot call itself.I have another class, copy of this class, but it works(I can add code).How I can resolve this error? using System; using System.Collections.Generic; using System.ComponentModel; using ImageCacher; namespace Delay { public class vkMessages : INotifyPropertyChanged { public string Kto { get; private set; } public DateTime Date_Time { get; private set; } public string InOrOut { get;

Angular2 RC BaseRequestOption Constructor Injection

╄→гoц情女王★ 提交于 2019-12-20 03:38:32
问题 I don’t know whether I am missing something but injecting the constructor of a custom baserequestoptions class was working fine for me in Beta 17 but after moving to RC1 this approach doesn’t seem to work any more. I have created a plunkr to illustrate that the webapibaseurl now comes through as undefined (the same code approach but with Beta 17 references worked): https://embed.plnkr.co/usOljRDLap9RlLd3RIBd/ Any ideas? 回答1: This still works for me. Here is the custom option class I used:

Java - Cannot find symbol constructor

点点圈 提交于 2019-12-20 03:33:20
问题 I'm completely new to Java, so I'm sorry if my question is dumb. Im working on this assignment, and I've been reading about main methods for hours now, but I just cant figure it out. I put some of my code below. I might be way off here, but what I'm hoping to accomplish is to get the main method to start the constructor, but when I compile I get an error saying "cannot find symbol - constructor Player". Now, Im guessing this has something to do with the string parameters of the constructor,

Constructor from initializer_list

 ̄綄美尐妖づ 提交于 2019-12-20 03:24:18
问题 I am implementing a container in c++, a wrapper for an array in fact. I am not sure how to implement a constructor from initializer_list. I end up with this implementation but it seems to me really ugly. So could be an array allocated in a heap initialized by an initializer_list. Or is there an elegant way how to do it? template <typename T> class sequence { public: sequence (size_t n): _data {new T[n]}, _size {n} {}; sequence (std::initializer_list<T> source); ~sequence() { delete[] _data; }

How to call constructor without new?

♀尐吖头ヾ 提交于 2019-12-20 02:42:37
问题 i know that string is like a class, and when creating a new string the string itself doesnt owe the value but only the value's pointer. but when creating a string there is no need to use the word new; string a = "hello"; and not string a = new string("hello"); I know that the second option is also possible but what i want to understand is why the first one? Let's say I have a class name student which he's constructor gets a string . To create a new class I must use the saved word new. student