当前位置:网站首页>指针与对象的一些注意事项
指针与对象的一些注意事项
2022-04-22 19:13:00 【What’smean】
定义一对类X和Y,其中X包含一个指向Y的指针,而Y包含一个类型为X的对象。
正确代码:
class X; //声明X
class Y{ //定义类型Y
X* x;
};
class X{ //定义类型X
Y y;
};
错误代码:
class Y; //声明X
class X{ //定义类型X
Y y;
};
class Y{ //定义类型Y
X* x;
};
代码说明:类X的声明称为前向声明,它向程序中引入了名字X并且指明X是一种类类型。对于类型X来说,此时我们已知它是一个类类型,但是不清楚它到底包含哪些成员,所以它是一个不完全类型。我们可以定义指向不完全类型的指针,但是无法创建不完全类型的对象。
版权声明
本文为[What’smean]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_42492218/article/details/124340356
边栏推荐
- 创建线程的四种方式
- postgre创建序列并绑定到表字段
- Postgre creates a sequence and binds it to a table field
- Line by line interpretation of redet code
- 09-Partitioning
- 14-Sprak设置自动分区
- With the rapid and savage growth of single chip microcomputer embedded industry, the demand of various posts also increases
- 静态分派和动态分派
- MySQL index
- 08-UDFs
猜你喜欢

Solution for C10K scenario of ICBC distributed service

【面试普通人VS高手系列】请说一下网络四元组

MySQL query with serial number

微服务调用组件Feign介绍

webrtc+turn+peerconnection_server测延时

Database index

.net core minimal api 上传文件

09-Partitioning

MCU infrared module knowledge sharing theory is the basis of practical combat in the future

The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
随机推荐
Can deleted photos be restored? 3 tips to restore deleted photos
Project training - Design and development of 2D multiplayer scuffle game based on unity (III. unity plasticscm multiplayer collaboration)
The third job analysis
Static dispatch and dynamic dispatch
With the rapid and savage growth of single chip microcomputer embedded industry, the demand of various posts also increases
MySQL query with serial number
AWSL! This wave of memories killed real love!
什么是 SAML 断言?
Pychar configures CONDA and uses the correct image source address in China
Will map () in JS change the original array
MCU infrared module knowledge sharing theory is the basis of practical combat in the future
2020-10-26 go language grpc learning
Redis的key和value最佳实践
. net core minimal API upload file
Introduction to high performance key value database redis
项目实训- 基于unity的2D多人乱斗闯关游戏设计与开发(五、利用AudioMixer控制音量大小)
工商银行分布式服务C10K场景的解决方案
mmocr DBLoss
被删除的相片能恢复吗?3个技巧恢复被删除的相片
Daily AI frontier term: Green AI