unique_ptr使用问题 #691
cellphonef
started this conversation in
General
Replies: 3 comments 1 reply
-
|
他们之间相互引用了,所以只能使用指针不能使用实体 |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
TcpServer中的acceptor_成员后面有一句注释avoid revealing Acceptor,翻译成中文就是避免暴露接受者,就是不让类Acceptor暴漏在当前头文件,所以只能用指针,为了自动释放,就用了unique_ptr,TcpConneciton中的socket_以及channel_成员也是同理,上面也有一行注释we don't expose those classes to client.,我们不向客户端公开这些类。不好意思我最开始说的互相引用指的是Channel和EventLoop,我以为你在说这个,刚刚去仔细看了下你的问题和源码 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
本意确实是“减少头文件的依赖”。 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
如TcpServer中的acceptor_成员和TcpConneciton中的socket_以及channel_成员,都使用unique_ptr来管理,个人觉得可以直接使用对象即可,想问muduo使用unique_ptr来管理是出于什么原因?减少头文件的依赖吗?
Beta Was this translation helpful? Give feedback.
All reactions