oop

difference between function hiding and overloading

£可爱£侵袭症+ 提交于 2021-02-04 18:07:21
问题 I can't find any difference between function hiding and overloading. As the function hiding is the function that is present in derived class and hides the function of a base class. Having same name of the function in both of them. Overloading: having same name but different signature in both derived and base class. class A { void print(int); }; class B: public A { void print(float); }; does it hide function or overload ? 回答1: The function B::print hides the parent function A::print . If you

Class declaration confusion - name between closing brace and semi-colon

Deadly 提交于 2021-02-04 17:59:07
问题 class CRectangle { int x, y; public: void set_values (int,int); int area (void); } rect; In this example, what does 'rect' after the closing brace and between the semi-colon mean in this class definition? I'm having trouble finding a clear explanation. Also: Whatever it is, can you do it for structs too? 回答1: rect is the name of a variable (an object in this case). It is exactly as if it had said: int rect; except instead of int there is a definition of a new type, called a CRectangle .

Python class design: explicit keyword arguments vs. **kwargs vs. @property

大兔子大兔子 提交于 2021-02-04 14:47:28
问题 Is there a generally accepted best practice for creating a class whose instances will have many (non-defaultable) variables? For example, by explicit arguments: class Circle(object): def __init__(self,x,y,radius): self.x = x self.y = y self.radius = radius using **kwargs: class Circle(object): def __init__(self, **kwargs): if 'x' in kwargs: self.x = kwargs['x'] if 'y' in kwargs: self.y = kwargs['y'] if 'radius' in kwargs: self.radius = kwargs['radius'] or using properties: class Circle(object

Python simple naked objects

醉酒当歌 提交于 2021-02-04 14:21:48
问题 What's the easiest way to create a naked object that I can assign attributes to? The specific use case is: I'm doing various operations on a Django object instance, but sometimes the instance is None (there is on instance). In this case I'd like to create the simplest possible fake object such that I can assign values to its attributes (eg. myobject.foo = 'bar' ). Basically I'm looking for the Python equivalent of this piece of Javascript: myobject = {} myobject.foo = 'bar' I know I can use a

Abstract Method in Non Abstract Class

≡放荡痞女 提交于 2021-02-04 09:18:24
问题 I want to know the reason behind the design of restricting Abstract Methods in Non Abstract Class (in C#). I understand that the class instance won't have the definition and thus they wont be callable, but when static methods are defined,they are excluded from the instance too. Why abstract methods are not handled that way, any specific reason for the same? They could be allowed in concrete class and the deriving class can be forced to implement methods, basically that is what, is done in

Correctly extend a tkinter widget using inheritance

无人久伴 提交于 2021-02-02 03:47:46
问题 Im kinda new to python classes and I dont know how to handle them well yet, and I promise I've done some research to solve this problem but still cant figure out how to. So, here it goes: I'm trying to use python classes to define tkinter widgets so I can implement them rather quickly. It all worked well with buttons and labels but with I cant get it with entries. I'll show you how I've coded buttons and labels to illustrate what im trying to do with entries as well (and maybe you guys can

Correctly extend a tkinter widget using inheritance

社会主义新天地 提交于 2021-02-02 03:42:32
问题 Im kinda new to python classes and I dont know how to handle them well yet, and I promise I've done some research to solve this problem but still cant figure out how to. So, here it goes: I'm trying to use python classes to define tkinter widgets so I can implement them rather quickly. It all worked well with buttons and labels but with I cant get it with entries. I'll show you how I've coded buttons and labels to illustrate what im trying to do with entries as well (and maybe you guys can

Correctly extend a tkinter widget using inheritance

给你一囗甜甜゛ 提交于 2021-02-02 03:42:06
问题 Im kinda new to python classes and I dont know how to handle them well yet, and I promise I've done some research to solve this problem but still cant figure out how to. So, here it goes: I'm trying to use python classes to define tkinter widgets so I can implement them rather quickly. It all worked well with buttons and labels but with I cant get it with entries. I'll show you how I've coded buttons and labels to illustrate what im trying to do with entries as well (and maybe you guys can

mysqli_query() expects parameter 1 to be mysqli, object given

早过忘川 提交于 2021-01-29 22:30:01
问题 I'm trying to create a class which can be used for connecting to MySQL database. This is my code: The class: <?php class createCon { var $host = 'localhost'; var $user = 'root'; var $pass = ''; var $db = 'example'; var $myconn; function connect() { $con = mysqli_connect($this->host, $this->user, $this->pass, $this->db); if (!$con) { die('Could not connect to database!'); } else { $this->myconn = $con; echo 'Connection established!';} return $this->myconn; } function close() { mysqli_close(

Double free or corruption (out) and how to check whether a destructor works properly [closed]

て烟熏妆下的殇ゞ 提交于 2021-01-29 18:23:54
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 months ago . Improve this question I am trying to improve my 2D array to be created using a class. All methods work fine, it is properly printed out and so on, but when I try to create a destructor I either get an error double free or corruption , I am able to get rid of the error message but then I am not sure