Use of deleted copy constructor in the singleton

前提是你 提交于 2019-12-03 16:28:53

Consider what you're trying to do here:

Settings_manager set = Settings_manager::get_instance();

You have your singleton, get_instance(), and you're trying to copy it? That would kind of defeat the purpose of singleton if you could just... create two of them right?

You want to take a reference:

Settings_manager& set = Settings_manager::get_instance();

This way, set is the singleton instance. Not a copy of it.

get_instance returns a reference to your singleton, which you then store in a local Settings_manager variable, which needs to make a copy. set should be a reference variable:

Settings_manager &set = Settings_manager::get_instance();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!