class

Typescript error: An outer value of 'this' is shadowed by this container

帅比萌擦擦* 提交于 2021-02-18 10:10:14
问题 I had an error in a Typescript class method declaration, but I don't understand how the error message relates back to the bug. The message seems to be saying that 'this' is of type any , but we are in a class definition, and so I thought 'this' was really clear. Can someone please explain how the error message relates back to the bug? Original method: calcSize = function() { return this.width * this.length; // Error on this line }; // Error text: 'this' implicitly has type 'any' because it

static const member variable initialization

冷暖自知 提交于 2021-02-18 05:36:50
问题 Looks like I can init a POD static const member, but not other types: struct C { static const int a = 42; // OK static const string b = "hi"; // compile error }; Why? 回答1: The syntax initializer in the class definition is only allowed with integral and enum types. For std::string , it must be defined outside the class definition and initialized there. struct C { static const int a = 42; static const string b; }; const string C::b = "hi"; // in one of the .cpp files static members must be

Why Java object class remains same after casting?

*爱你&永不变心* 提交于 2021-02-18 05:34:06
问题 I tried to upcast an objet. But at runtime object class is remained as a derived class. Derived drv = new Derived(); Base base = (Base) drv; System.out.println("Class : " + base.getClass()); //prints -> Class : class packagename.Derived So Why class property didn't change? 回答1: So Why class property didn't change? Because the object hasn't changed, just the type of the reference you have to it. Casting has no effect at all on the object itself. In Java, unlike some other languages (thankfully

TypeScript: class composition

一笑奈何 提交于 2021-02-18 05:23:51
问题 Based on this awesome Composition over Inheritance video by MPJ, I've been trying to formulate composition in TypeScript. I want to compose classes , not objects or factory functions. Here is my effort so far (with a little help from lodash ): class Barker { constructor(private state) {} bark() { console.log(`Woof, I am ${this.state.name}`); } } class Driver { constructor(private state) {} drive() { this.state.position = this.state.position + this.state.speed; } } class Killer { constructor

PHP two methods with the same name

十年热恋 提交于 2021-02-17 21:29:57
问题 Can I have two methods sharing the same name, but with different arguments? One would be public static and would take 2 arguments, the other one just public and takes only one argument example class product{ protected $product_id; public function __construct($product_id){ $this->product_id = $product_id; } public static function getPrice($product_id, $currency){ ... } public function getPrice($currency){ ... } } 回答1: I'm just giving you the super lazy option: function __call($name, $args) {

Beginner Python: AttributeError: 'list' object has no attribute

折月煮酒 提交于 2021-02-17 12:24:26
问题 The error says: AttributeError: 'list' object has no attribute 'cost' I am trying to get a simple profit calculation to work using the following class to handle a dictionary of bicycles: class Bike(object): def __init__(self, name, weight, cost): self.name = name self.weight = weight self.cost = cost bikes = { # Bike designed for children" "Trike": ["Trike", 20, 100], # Bike designed for everyone" "Kruzer": ["Kruzer", 50, 165] } When I try to calculate profit with my for statement, I get the

Beginner Python: AttributeError: 'list' object has no attribute

烈酒焚心 提交于 2021-02-17 12:24:13
问题 The error says: AttributeError: 'list' object has no attribute 'cost' I am trying to get a simple profit calculation to work using the following class to handle a dictionary of bicycles: class Bike(object): def __init__(self, name, weight, cost): self.name = name self.weight = weight self.cost = cost bikes = { # Bike designed for children" "Trike": ["Trike", 20, 100], # Bike designed for everyone" "Kruzer": ["Kruzer", 50, 165] } When I try to calculate profit with my for statement, I get the

C# error - Not all code paths return value

陌路散爱 提交于 2021-02-17 07:16:12
问题 So guys I know that have another posts like this with this name,but the other posts didn't help me find some solution for my problem. I have 1 Form and 4 Class with methods,and It's getting problem in the Class called Costs,that get's all the other 3 Class and put in him. I will post here the four classes. First Class - Alimentaçao using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Projeto

Detecting class attribute value change and then changing another class attribute

亡梦爱人 提交于 2021-02-17 07:10:30
问题 Let's say I have a class called Number class Number(): def __init__(self,n): self.n=n self.changed=None a = Number(8) print(a.n) #prints 8 a.n=9 print(a.n) #prints 9 When the n class attribute changes, I want the changed class attribute to be changed to True . 回答1: Possible with proper use of @propety class Number(): def __init__(self,n): self._n=n self._changed=None @property def n(self): return self._n @property def changed(self): return self._changed @n.setter def n(self, val): # while

How to access QString value from one class (window UI) in another class?

孤人 提交于 2021-02-17 07:06:35
问题 I am about to program a small desktop application to capture the working times of my fellow co-workers. It must be customized to our needs, therefore a commercial solution is not an option (+ we have no money). I am using Qt (5.11.2) and C++. I have a MainWindow (first window UI) that uses auto-completion to get the information (ID, Names, Group Leaders, ...) from a sqlite3 database and fill the QLineEdits. This part is working just fine. Now, I have created a second window UI to capture the