我想从函数返回一个类的实现.该功能在库中.我想阻止用户销毁我返回的对象.我怎样才能做到这一点?
编辑:示例.
与世界的接口:
class Base
{
public:
virtual void foo() = 0;
};
Base* GetFoo();
Run Code Online (Sandbox Code Playgroud)
实施 - 内部:
class Bar : public Base
{
public:
void foo() { //Do something}
};
Base* GetFoo()
{
return new Bar
}
Run Code Online (Sandbox Code Playgroud)