virtual

定义类成员

蹲街弑〆低调 提交于 2020-02-04 13:51:39
访问级别: public private internal 成员只能由定义它的项目(程序集)内部的代码访问 protected 成员只能由类或派生类中的代码访问 protected internal 只能由项目(程序集)中派生类的代码来访问 定义字段: readonly: 表示这个字段只能在执行构造函数的过程中赋值,或由初始化赋值语句赋值 static:静态字段 定义方法: static virtual 方法可重写 abstract 方法必须在非抽象的派生类中重写(只用于抽象类中) override 方法重写了一个基类方法(如果方法被重写,就必须用该关键字) extern 方法定义放在其他地方 override sealed 方法不能由派生类重写 定义属性: private int myInt; public int MyIntProp { get{return myInt;} set{myInt=value;} } 属性可以使用virtual,override,abstract 关键字,但这几个关键字不能用在字段中。 自动属性 public int MyIntProp { get; set; } C#编译器会添加未输入的内容,编译哭会声明一个用于存储属性的私有字段,并在属性的get和set块中使用该 字段。 我们以通常的方式定义属性的可访问性,类型和名称

ansible facts使用

假装没事ソ 提交于 2020-02-02 23:52:09
ansible facts 采集被管理设备的一个功能 [ root@192-168-2-250 ~ ] # ansible rongkang -m setup 172.20.100.108 | SUCCESS = > { "ansible_facts" : { "ansible_all_ipv4_addresses" : [ "172.18.0.1" , "172.17.0.1" , "172.20.100.108" ] , "ansible_all_ipv6_addresses" : [ "fe80::78c4:b7ff:feac:4775" , "fe80::b05d:f6ff:fe63:1f18" , "fe80::42:40ff:fe03:25e6" , "fe80::c14a:4493:465b:199b" ] , "ansible_apparmor" : { "status" : "disabled" } , "ansible_architecture" : "x86_64" , "ansible_bios_date" : "04/01/2014" , "ansible_bios_version" : "1.10.2-3.el7_4.1" , "ansible_br_94a16b290723" : { "active" : true, "device" : "br

Simulate Microphone (virtual mic)

雨燕双飞 提交于 2020-02-01 16:07:29
问题 I've got a problem where I need to "simulate" microphone output. Data will be coming over the network, decoded into PCM and basically needs to be written into the mic - which then other programs can read/record/whatever. I've been reading up on alsa but information is pretty sparse. The file plugin seemes promising - I was thinking of having a named pipe as "infile" which I could then deliver data to from my application. I can't get it to work however (vlc/audacity just segfault). pcm.testing

Simulate Microphone (virtual mic)

梦想与她 提交于 2020-02-01 16:05:18
问题 I've got a problem where I need to "simulate" microphone output. Data will be coming over the network, decoded into PCM and basically needs to be written into the mic - which then other programs can read/record/whatever. I've been reading up on alsa but information is pretty sparse. The file plugin seemes promising - I was thinking of having a named pipe as "infile" which I could then deliver data to from my application. I can't get it to work however (vlc/audacity just segfault). pcm.testing

多态的概念和意义

限于喜欢 提交于 2020-02-01 14:23:28
函数重写回顾 父类中被重写的函数依然会继承给子类 子类中重写的函数将覆盖父类中的函数 通过作用域分辨符(::)可以访问父类中的函数 Chidl c; Parent*p = &c; c.Parent::print(); //在父类中继承 c.print(); //在子类中重写 p->print(); //父类中定义 面向对象中期望的行为? 根据实际的对象类型判断如何调用重写函数,父类指针(引用)指向父类对象则调用父类中定义的函数,如果指向子类对象则调用子类中定义的重写函数。 面向对象中多态的概念? 根据实际的对象类型决定函数调用的具体目标,同样的语句在实际运行时有多重不同的表现形态 C++语言支持多态的概念 通过使用virtual关键字对多态进行支持 被virtual声明的函数被重写后具有多态特性 被virtual声明的函数叫做虚函数 实验 #include <iostream> #include <string> using namespace std; class Parent { public: virtual void printf() { cout << "I'm Parent" << endl; } }; class Child :public Parent { public: void printf() { cout << "I'm Child" << endl; }

What happens when delete a polymorphic object without a virtual destructor?

核能气质少年 提交于 2020-02-01 08:21:27
问题 In following example, b is a polymorphic pointer type whose static type is Base* and whose dynamic type is Derived* . struct Base { virtual void f(); }; struct Derived : Base { }; int main() { Base *b = new Derived(); // ... delete b; } What happens when b is deleted without a virtual destructor? 回答1: What happens when b is deleted without a virtual destructor? We don't know. The behavior is undefined. For most actual cases the destructor of Derived might no be invoked, but nothing is

What if the virtual destructor defined in derived class, but not the top of hierarchy? C++

戏子无情 提交于 2020-01-30 12:25:12
问题 I wonder is it correct to define a base class with no virtual destructor, and define inherited classes with the virtual one? What would actually happen if I do that? 回答1: If you delete p where p is of type X* but actually points to a Y which is derived from X , you have undefined behavior unless X has a virtual destructor. If Y 's destructor is virtual but X s destructor is not it changes exactly nothing. 回答2: If you intend to do delete pB; where pB is of type Base* and pB might point to an

C++内存布局之虚拟继承

北城以北 提交于 2020-01-29 08:55:50
虚拟继承 即派生类继承多次基类,但在派生类中只存在一份基类的拷贝。编译器实现虚拟继承的方式并不相同,下面我结合VS2010来探讨C++虚拟继承。声明一个虚基类CommonBase,两个从虚基类虚拟派生Base1和Base2,然后D,公有多继承自Base1和Base2,具体类定义如下: class CommonBase { public: virtual void commonBaseFunc() = 0; private: int commonBase_data; }; class Base1 : public virtual CommonBase { public: virtual void Base1_Fun1(){} virtual void Base1_Fun2(){} virtual void commonBaseFunc(){} private: int Base1_data; }; class Base2 : public virtual CommonBase { public: virtual void Base2_Fun1(){} virtual void Base2_Fun2(){} private: int Base2_data; }; class Derived : public Base1, public Base2 { public: virtual

C++虚函数 - 静态函数能否为虚函数

我的梦境 提交于 2020-01-29 05:27:56
1.virtual与静态函数 C++中,静态成员函数不能被声明为virtual函数。 例如,下面的程序会编译失败。 class Test { public: // 编译错误:static成员函数不能声明为virtual virtual static void fun() { } }; 同样地,静态成员函数也不能被声明为const和volatile. 下面的程序也会编译失败。 class Test { public: // 编译错误: static成员函数不能为const static void fun() const { } // 如果声明为下面这样,是可以的。 const static void fun() {} 或类似于 const static int fun() { return 0; } }; 2.为何static成员函数不能为virtual static成员不属于任何类对象或类实例,所以即使给此函数加上virutal也是没有任何意义的。 静态与非静态成员函数之间有一个主要的区别。那就是静态成员函数没有this指针。 虚函数依靠vptr和vtable来处理。vptr是一个指针,在类的构造函数中创建生成,并且只能用this指针来访问它,因为它是类的一个成员,并且vptr指向保存虚函数地址的vtable. 对于静态成员函数,它没有this指针,所以无法访问vptr.

c/c++常见面试题一

╄→гoц情女王★ 提交于 2020-01-29 04:04:13
找工作这么多天了,贴一下常见基础题吧,谁找工作了还可以复习下。答案有的是缺少很多,想看全百度之谷歌之... 1.进程与线程的区别:   很长重点写了:一个程序必须有一个进程,一个进程要有一个线程。   进程在运行时有独立的内存单元,而线程则是共享内存单元,所以一个线程死掉这个进程就会死掉,但是一个进程死掉程序无所谓。所以多进程程序比多线程要      稳定。   2.c++函数传递参数的方式:   1.直接传递、引用、指针。   他们的优缺点:   1.按值传递,在传递的时候实参被复制了一份,然后在函数体内使用。如果修改函数体内的拷贝,而实参是没有改变的。   2.引用是别名,所以效率别指针快,也比指针安全。(优先使用引用而不使用指针)   3.按值传递和引用传递在传参过程中,都执行强类型检查,而指针传递的类型比较弱,如果参数被声明为void*基本上没有类型检查,只要是指针编译器就认为是合法的,所以这会造成BUG。   4.指针可以干引用的活,而且还可以传递空指针,特别函数特别应用。但是指针用起来本身就很麻烦,如非需要还是不用。 *3.什么是深拷贝和浅拷贝    深拷贝:拷贝了对象的资源,在新对象中又建立了一个新的字段把资源放进去,如果修改其一,另一个不会改变。    浅拷贝:没有拷贝对象资源,它们共享资源,如果改变其一另一个也会随之改变。 4.面向对象的三个基本特征   1)封装