C ++ singleton GetInstance()返回 [英] C++ singleton GetInstance() return

查看:120
本文介绍了C ++ singleton GetInstance()返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中实现单例时,GetInstance()是否更好地返回指向单例对象或引用的指针?是真的吗?

When implementing a singleton in C++, is it better for GetInstance() to return a pointer to the singleton object, or a reference? Does it really matter?

推荐答案

我更喜欢参考。在我要记录的时候,我使用引用而不是指针:

I prefer a reference. I use reference instead of a pointer whenever I want to document that:


  • 不能为空

  • 不会更改(指向其他内容)

  • 不能删除

这篇关于C ++ singleton GetInstance()返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆