如何在只有受保护或私有构造函数的类上调用:std:make_Shared?
testmakeshared.cpp
#include <memory>class A {
public:
static ::std::shared_ptr<A> create() {
return ::std::make_shared<A>();
}
protected:
A() {}
A(const A &) = delete;
const A &operator =(const A &) = delete;};::std::shared_ptr<A> foo(){
return A::create();}g++ -std=c++0x -march=native -mtune=native -O3 -Wall testmakeshared.cppIn file included from /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../i nclude/c++/4.6.1/bits/shared_ptr.h:52:0, from /usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../include/c++/4.6.1/memory:86,++/4.6.1/bits/shared_ptr_base.h: 400:2: error: within this contextCompilation exited abnormally with code 1 at Tue Nov 15 07:32:58
::std::make_shared
::std::make_shared::std::shared_ptr
红颜莎娜
开心每一天1111
随时随地看视频慕课网APP
相关分类