class

python(继承)

*爱你&永不变心* 提交于 2020-01-07 22:44:06
python中继承分为单继承或多继承。父类称为基类。 子类继承了父类的所有属性。 子类调用属性时,先在自己的属性中找,找不到才到父类属性中找。 # -*- coding: utf-8 -*- class Dad: '这个是父类' money=100 def __init__(self,name): print('父亲') self.name=name def Play(self): print('%s正在工作'%self.name) #单继承==>子类(父类) class Son(Dad): money = 2000 print(Dad.money) print(Son.money) son_1=Son('小明') son_1.Play() print(son_1.name) 子类和父类存在相同属性情况 # -*- coding: utf-8 -*- class Dad: '这个是父类' money=100 def __init__(self,name): print('父亲') self.name=name def Play(self): print('%s正在工作'%self.name) #单继承==>子类(父类) class Son(Dad): money = 2000 def __init__(self,name,age): self.name=name self.age

使用'class'或'typename'作为模板参数? [重复]

眉间皱痕 提交于 2020-01-07 21:02:15
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 可能重复: 模板中关键字'typename'和'class'的C ++差异 在C ++中定义函数模板或类模板时,可以这样写: template <class T> ... 或者可以这样写: template <typename T> ... 是否有充分理由偏好一个而不是另一个? 我接受了最受欢迎(也很有趣)的答案,但真正的答案似乎是“不,没有理由更喜欢一个而不是另一个。” 它们是等价的(除非如下所述)。 有些人有理由总是使用 typename 。 有些人有理由总是使用 class 。 有些人有理由同时使用这两种方法。 有些人并不关心他们使用哪一个。 但请注意,在 模板模板 参数的情况下,在C ++ 17之前,需要使用 class 而不是 typename 。 请参阅下面的 user1428839的答案 。 (但这个特殊情况不是偏好问题,而是语言的要求。) #1楼 forced (up to and including C++14) when dealing with parameters, eg: 作为除了所有上述职位,使用的 class 关键字强制(直至并包括C ++ 14)与的参数,例如当处理: template <template <typename, typename> class Container,

C#-where关键字用法

[亡魂溺海] 提交于 2020-01-07 18:12:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 接口约束 public class MyGenericClass < T > where T: IComparable { } 基类约束:指出某个类型必须将指定的类作为基类(或者就是该类本身),才能用作该泛型类型的类型参数。这样的约束一经使用,就必须出现在该类型参数的所有其他约束之前。 class MyClassy < T, U > where T : class where U : struct { } where 子句还可以包括构造函数约束。 public class MyGenericClass < T > where T: IComparable , new () { // The following line is not possible without new() constraint: T item = new T(); } new() //约束出现在 where 子句的最后。 对于多个类型参数,每个类型参数都使用一个 where 子句 interface MyI { } class Dictionary < TKey, TVal > where TKey: IComparable , IEnumerable where TVal: MyI { public void Add(TKey key,

Difference between “::” “.” and “->” in c++

99封情书 提交于 2020-01-07 09:55:20
问题 I have found the class Kwadrat. The author used three types of operator ::, . and ->. The arrow is the one that only works. What's the difference between those three? #include <iostream> using namespace std; class Kwadrat{ public: int val1, val2, val3; Kwadrat(int val1, int val2, int val3) { this->val1 = val1; //this.val2 = val2; //this::val3 = val3; } }; int main() { Kwadrat* kwadrat = new Kwadrat(1,2,3); cout<<kwadrat->val1<<endl; cout<<kwadrat->val2<<endl; cout<<kwadrat->val3<<endl; return

How do I do in Eclipse to build my custom java package and project at the same time?

有些话、适合烂在心里 提交于 2020-01-07 09:24:07
问题 It's said that a java package may contain classes, interfaces, enums, ... but I've been seeking over the net and I still haven't found what I'm looking for ... When I see package info files they also include classes... My idea is that package defines classes, interfaces, etc. in the same file but the code of the class should be in a separate class file, shouldn't it? Should I name the same package in each class I create for Eclipse to put them all together under the same package without the

Class App\Http\Controllers\PostConstroller does not exist

谁说我不能喝 提交于 2020-01-07 09:23:58
问题 Hello I try to create post with Laravel, but I have this error : Class App\Http\Controllers\PostConstroller does not exist Route: Route::get('/', function () { return view('welcome'); }); Auth::routes(['verify' => true]); Route::get('/home', 'HomeController@index')->name('home'); Route::get('/profile/{user}', 'ProfileController@show')->name('profile.show'); Route::get('/posts/create', 'PostConstroller@create')->name('posts.create'); Route::post('/posts', 'PostConstroller@store')->name('posts

as3 how to change a number by a class?

拜拜、爱过 提交于 2020-01-07 09:20:35
问题 The following code isn't working: package { public class num { public function num() { } public function numto(num1:Number) { num1 = 47; } } } when I use in my main timeline: import num; var n:Number = 17; numto(n); trace(n); // must be 47 instead of 17 It gives me different error messages such as: access of undefined property numto; 回答1: You should try to learn basics of Actionscript language. Read some general books, it will help you to understand what is going on. As to your question

Why is my code coming out with the wrong output? Is my insert class wrong?

自作多情 提交于 2020-01-07 08:32:20
问题 I have to create classes to be implemented with the main class someone else has and for some reason I am not getting the right outputs, I'm not sure is my calculations are off which I don't think they are or my insert class is wrong. Expected Output: Median = 44.5 Mean = 49.300 SD = 30.581 Actual Output: Median = 0.0 Mean = 0.967 SD = 4.712 public class StatPackage { int count; double [] scores; final int MAX = 500; StatPackage() { count = 0; scores = new double[MAX]; } public void insert

Why is my code coming out with the wrong output? Is my insert class wrong?

南笙酒味 提交于 2020-01-07 08:31:09
问题 I have to create classes to be implemented with the main class someone else has and for some reason I am not getting the right outputs, I'm not sure is my calculations are off which I don't think they are or my insert class is wrong. Expected Output: Median = 44.5 Mean = 49.300 SD = 30.581 Actual Output: Median = 0.0 Mean = 0.967 SD = 4.712 public class StatPackage { int count; double [] scores; final int MAX = 500; StatPackage() { count = 0; scores = new double[MAX]; } public void insert

ISO C++ forbids declaration of 'myStruct' with no type

余生颓废 提交于 2020-01-07 08:13:28
问题 Here is my code DeviceClass.cpp: ... #include "myHeader.h" class DeviceClass : public DeviceClassBase { private: myClass::myStruct Foo; Foo.one = 1; Foo.two = 2; myClass myclass(Foo); ... }; This is myClass from the myHeader.h file: class myClass : baseClass{ public: struct myStruct { myStruct(): one(0), two(0){} int one; int two; }; myClass(const myStruct &mystruct); }; But this is failing to compile. I get this error: : error: ISO C++ forbids declaration of 'myStruct' with no type : error: