我有一堂课:
class SymbolIndexer {
protected:
SymbolIndexer ( ) { }
public:
static inline SymbolIndexer & GetUniqueInstance ( )
{
static SymbolIndexer uniqueinstance_ ;
return uniqueinstance_ ;
}
};
我应该如何修改它以禁用如下代码:
SymbolIndexer symbol_indexer_ = SymbolIndexer::GetUniqueInstance ( );
并且只允许这样的代码:
SymbolIndexer & ref_symbol_indexer_ = SymbolIndexer::GetUniqueInstance ( );
您可以将复制构造函数设为私有并且不提供任何实现:
private:
SymbolIndexer(const SymbolIndexer&);
或者在C++11中,明确禁止它:
SymbolIndexer(const SymbolIndexer&) = delete;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)