class

Different ways of initializing an object in c++

痞子三分冷 提交于 2020-01-22 08:02:59
问题 I'm pretty sure this is a duplicate question, but I've been searching for a while and I didn't get any smarter. Imagine this class: class Entity { public: int x, y; Entity() : x(0), y(0) { } Entity(int x, int y) : x(x), y(y) { } } And here are multiple ways of initializing the class: Entity ent1; Entity ent2(); Entity ent3(1, 2); Entity ent4 = Entity(); Entity ent5 = Entity(2, 3); I also know that's it's possible make an object on the heap memory, but that's not a great mystery to me at this

PHP: self:: vs parent:: with extends

我只是一个虾纸丫 提交于 2020-01-22 05:19:17
问题 I'm wondering what is the difference between using self:: and parent:: when a static child class is extending static parent class e.g. class Parent { public static function foo() { echo 'foo'; } } class Child extends Parent { public static function func() { self::foo(); } public static function func2() { parent::foo(); } } Is there any difference between func() and func2() and if so then what is it ? Thank you Regards 回答1: Child has foo() Parent has foo() self::foo() YES YES Child foo() is

How to duplicate blocks of widgets in kv file (lowercase-only rule)

荒凉一梦 提交于 2020-01-22 03:08:05
问题 I try to understand how kivy .kv files work, so I created a small application with a horizontial BoxLayout which contains three GridLayouts, as shown: my_widget: <my_widget@BoxLayout>: orientation: "horizontal" GridLayout: rows: 3 ToggleButton: Image: Label: GridLayout: rows: 3 ToggleButton: Image: Label: GridLayout: rows: 3 ToggleButton: Image: Label: No problem there, but since there are same blocks of widgets (GridLayouts) could they be duplicated? I tried something like: https://kivy.org

Clear output widget using onclick Button event - Python

我的未来我决定 提交于 2020-01-22 02:21:12
问题 I am working on a Jupyter Notebook in which I am using a button created with ipywidgets to display a df when clicking on it. For this I am using the following code: import ipywidgets as widgets import numpy as np vartest = 0 Button = widgets.Button(description='Search', disabled=False, button_style='info', tooltip='Search') display(Button) def whenclick2(b): global df if vartest==0: df = pd.DataFrame(np.arange(5)) class displayDF(object): def _create_widgets(self): self.button = Button self

Initiating a class from string with extra step?

a 夏天 提交于 2020-01-21 19:41:09
问题 I've been looking into substantiating a new class instance from a string in PHP. This is seems to be an acceptable procedure, however I am curious why it can't be done with the returns of a function call. I posted a short test below, and my results indicate it works if there is a variable intermediary (i.e. $bar = new $foo->callBar(); does not work, while $x = $foo->callBar(); $bar = new $x; does). class Foo { function callBar() { return 'Bar'; } } class Bar { function sayHi() { echo 'Hi'; }

What is the difference writing code in a class and in def __init__(self) in Python? [duplicate]

北城以北 提交于 2020-01-21 18:59:49
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Variables inside and outside of a class __init__() function I understand that when a class is called it will run the code in __init__ before anything. I still don't see the difference between that, and writing the code directly under the class. For example: class main(): x = 1 def disp(self): print self.x class main(): def __init__(self): self.x = 1 def disp(self): print self.x To me, both have the same

Get all Fields of class hierarchy [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-21 15:12:07
问题 This question already has answers here : Retrieving the inherited attribute names/values using Java Reflection (13 answers) Closed 8 months ago . I have classes: ClassA{ public String filedA; } ClassB extends ClassA{ public String filedB; } ClassC extends ClassB{ public String filedC; } Then I create object: ClassC c=new ClassC(); c.fieldC="TestC"; c.fieldA="TestA"; c.fieldB="TestB"; After I try get all fields, I call Field[] fields=c.getClass().getDeclaredFields(); But I get array with only

How to Get class of Elements that List Contains?

梦想与她 提交于 2020-01-21 11:05:44
问题 I have a list like that: private List<T> myList = new ArrayList<T>(); I want to get the .class of T. How can I do that? I mean as like: myList.getClass() EDIT: I tried that: Field genericField = Wrapper.class.getDeclaredField("myList"); ParameterizedType genericType = (ParameterizedType) genericField.getGenericType(); Class<?> genericClass = (Class<?>) genericType.getActualTypeArguments()[0]; and when I debug it genericType has a value of: java.util.List so I think that this is certainly

How to Get class of Elements that List Contains?

人走茶凉 提交于 2020-01-21 11:04:07
问题 I have a list like that: private List<T> myList = new ArrayList<T>(); I want to get the .class of T. How can I do that? I mean as like: myList.getClass() EDIT: I tried that: Field genericField = Wrapper.class.getDeclaredField("myList"); ParameterizedType genericType = (ParameterizedType) genericField.getGenericType(); Class<?> genericClass = (Class<?>) genericType.getActualTypeArguments()[0]; and when I debug it genericType has a value of: java.util.List so I think that this is certainly

How to use variables defined in a public class in other classes in java?

南笙酒味 提交于 2020-01-21 09:49:09
问题 A layman's question on the definition and use of variables: I need to make a Java GUI that gets user's input and stores it within a text file. However this writing has to be done inside an Actionlistener class (ie, user is clicking the button and text file is created and stored). This means that I have to define a variable in one class (public class) and use it in another (the one that defines the Actionlistener). How can I do this? Are global variables the only way? In my code I first define