关于class
struct Test
{
int x;
int y;
int z; void Init(int x,int y,int z);
void Function1();
void Function2();
void Function3();
};
void Test::Init(int x,int y,int z)
{
this->x = x;
this->y = y;
this->z = z;
}
void Test::Function1()
{
printf("Function1:%x\n",x);
}
void Test::Function2()
{
printf("Function2:%x\n",y);
}
void Test::Function3()
{
printf("Function3:%x\n",z);
}
private:
int x;
public:
int y;
void Init(int x,int y)
{
this->x = x;
this->y = y;
}
}; Test t;
t.Init(,); int* p = (int*)&t;
int n = *p;
int m = *(p+);
printf("%d %d\n",n,m);
class Base
{
int x;
int y;
}; int main(int argc, char* argv[])
{
Base base; base.x = ;
base.y = ; return ;
}
class Base
{
public:
int x;
int y;
}; class Sub:Base
{
public:
int a;
int b;
}; int main(int argc, char* argv[])
{
Sub sub; sub.x = ; //无法访问
sub.y = ; //无法访问
sub.a = ;
sub.b = ; return ;
} 父类中的程序继承后变成private属性;
也就是默认:
class Sub:private Base
{
public:
int a;
int b;
};
如果不希望改变成员的属性,需要在继承时声明public:
class Sub:public Base
{
public:
int a;
int b;
};
class Base
{
public:
Base()
{
x = ;
y = ;
}
private:
int x;
int y;
}; class Sub:Base
{
public:
int a;
int b;
}; int main(int argc, char* argv[])
{
Sub sub;
sub.a = ;
sub.b = ; int* p = (int*)⊂ printf("%d\n",sizeof(sub));
printf("%d\n",*(p+));
printf("%d\n",*(p+));
printf("%d\n",*(p+));
printf("%d\n",*(p+)); return ;
}
随机推荐
- Feign【开启GIZP压缩】
SpringCloudFeign支持对请求和响应进行gzip压缩,以此来提高通信效率. 1.搭建gzip-demo工程 1.1.工程依赖: <parent> <groupId> ...
- 串口(USART)通信-串口通讯协议简介
物理层:规定通讯系统中具有机械.电子功能部分的特性,确保原始数据在物理媒体的传输.其实就是硬件部分. 协议层:协议层主要规定通讯逻辑,统一收发双方的数据打包.解包标准.其实就是软件部分. 简单来说物理 ...
- Yii2 设计模式——单例模式
单例模式 模式定义 单例模式确保一个类只有一个实例,并提供一个全局访问点.当现实中只需要一个对象,或者为了节省系统资源,又或者是为了共享数据的时候可以使用单例模式. 代码实现 我们先来看看单例模式的标 ...
- 【百度之星2019】Strassen
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6719 在本题中,我们只有两种方法计算两个的矩阵的乘积,第一种为定义法,需要次乘法和次加法.第二种为 ...
- 怎样理解数组的空元素empty与undefined的区别
数组的空元素empty表示空位, 它不是一种数据类型, 而是由于人为修改arr.length 或者写入时多写了逗号造成的. var arr = [1,2,3,4,,,5]; arr.length; a ...
- sping+redis实现消息队列的乱码问题
使用spring支持redis实现消息队列,参考官方样例:https://spring.io/guides/gs/messaging-redis/ 实现后在运行过程中发现消费者在接收消息时会出现乱码的 ...
- (三)使用Intent在活动中穿梭:显式和隐式Intent
一.显式Intent @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstan ...
- “org/apache/commons/logging/LogFactory”错误的解决方式
用spring-framework-4.2.6.RELEASE-dist时,发生了如下的错误: [java] view plain copy Exception in thread "mai ...
- luogu2657-Windy数题解--数位DP
题目链接 https://www.luogu.org/problemnew/show/P2657 分析 第一道数位DP题,发现有点意思 DP求\([L,R]\)区间内的XXX个数,很套路地想到前缀和, ...
- springboot启动流程(十)springboot自动配置机制
所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 在第七篇文章中我们了解到,refresh过程将会调用ConfigurationClass ...