对C++下struct 和 类默认继承的认识
#include <iostream>
using namespace std;
struct struct1{
int data1 ;
double data2 ;
struct1(){
(*this).data1 = data1 ;
(*this).data2 = data2 ;
cout<<"this is output by struct1 function !";
}
public :
void privateFunc(){
cout<<"this is private function , so this massage should never show in console ! \n";
}
};
struct struct2 : struct1{
/* according the result in console , we can get the conclusion : the default inherit method of struct is public */
};
class class1 : public struct1 {
/* if ignore 'public' identifiers , compile will show that privateFunc() in 35 line can't access, this indicate that it is private inhert when subclass is a struct. */
string name ;
public :
class1(){
name = "i'm a class !";
cout<<"this is output by class1 !";
}
};
class class2{
public :
void showClass2(){
cout<<"this is output by class2 ! \n ";
}
};
class class3 : class2{
/* according to the result : showClass2 can't accessiable can prove class default inherit method is private */
};
struct struct4 : class2{
/* default inherit is public */
};
class class4 : struct1 {
/* default inherit is private
*/
}
int main(){
//struct2 onestruct2 ;
//onestruct2.privateFunc();
/* test class default inherit */
//class3 * oneclass3 = class3;
//oneclass3->showClass2();
/* test struct inherit class */
//struct4 onestruct4 ;
//onestruct4.showClass2();
class4 * oneclass4;
oneclass4->privateFunc();
return ;
}
对C++下struct 和 类默认继承的认识的更多相关文章
- Python基础(16)_面向对象程序设计(类、继承、派生、组合、接口)
一.面向过程程序设计与面向对象程序设计 面向过程的程序设计:核心是过程,过程就解决问题的步骤,基于该思想设计程序就像是在设计一条流水线,是一种机械式的思维方式 优点:复杂的问题的简单化,流程化 缺点: ...
- java面向对象类的继承~ 匿名类 ;多态特性;强制类型转换
类的继承 创建子类语法: 修饰符 class 子类名 extends 父类名{ } 匿名子类语法: 直接实例化,过程中通过匿名类 继承父类,在实例化过程中将子类匿名 <父类 ...
- Java类是如何默认继承Object的
前言 学过Java的人都知道,Object是所有类的父类.但是你有没有这样的疑问,我并没有写extends Object,它是怎么默认继承Object的呢? 那么今天我们就来看看像Java这种依赖于虚 ...
- Java类是如何默认继承Object的?
原:https://juejin.im/post/5ca1e8ade51d454e6a300048 前言 学过Java的人都知道,Object是所有类的父类.但是你有没有这样的疑问,我并没有写exte ...
- Python基础总结之初步认识---class类的继承(下)。第十五天开始(新手可相互督促
年薪百万的步伐慢了两天hhhh严格意义是三天.最近买了新的玩具,在家玩玩玩!~~~~ 今天开始正式认识类的继承.类的继承是怎么继承呢?看下代码: class Animal(object): #父类 d ...
- javascript类式继承模式#1——默认模式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- c#中结构体(struct)和类(class)的区别
一.类与结构的示例比较: 结构示例: public struct Person { string Name; int height; int weight public bool overWeight ...
- [C++]类的继承与派生
继承性是面向对象程序设计的第二大特性,它允许在既有类的基础上创建新类,新类可以继承既有类的数据成员和成员函数,可以添加自己特有的数据成员和成员函数,还可以对既有类中的成员函数重新定义.利用类的继承和派 ...
- 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...
随机推荐
- JavaScript设计模式——单体模式
一:单体模式简介: 是什么:将代码组织为一个逻辑单元,这个单元中的代码通过单一的变量进行访问.只要单体对象存在一份实例,就可以确信自己的所有代码使用的是同样的全局资源. 用途:1.用来划分命名空间,减 ...
- Angular JS 学习之Http
1.$http是AngularJS中的一个核心服务,用于读取远程服务器的数据: 2.读取JSON文件: **JSON文件如下: { "sites":[ { "Name&q ...
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8481 Accepted: 5479 Description In an ...
- Codeforces Round #342 (Div. 2)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- BFS HDOJ 2102 A计划
题目传送门 题意:中文题面 分析:双层BFS,之前写过类似的题.总结坑点: 1.步数小于等于T都是YES 2. 传送门的另一侧还是传送门或者墙都会死 3. 走到传送门也需要一步 #include &l ...
- Gym100685G Gadget Hackwrench(倍增LCA)
题目大概说一棵边有方向的树,q个询问,每次询问结点u是否能走到v. 倍增LCA搞即可: 除了par[k][u]表示u结点往上走2k步到达的结点, 再加上upp[k][u]表示u结点往上走2k步经过边的 ...
- WPF:在ControlTemplate中使用TemplateBinding
A bit on TemplateBinding and how to use it inside a ControlTemplate. Introductio Today I'll try to w ...
- Fetch from Upstream 变灰失效
Team——>Remote——>Configure Fetch from Upstream… Team——>Remote——>Configure Push to Upstre ...
- 【转】推荐UML插件AmaterasUML
基于Green UML在使用过程中的问题(对于大工程,点击生成类图后不响应),自己只能再次寻找其他的插件.在无意中,发现AmaterasUML. 官方网站:http://amateras.source ...
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
#include <iostream> #include <algorithm> #include <vector> #include <numeric> ...