Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Created February 19, 2015 16:22
Show Gist options
  • Save iwagaki/83dba6453037860a49f7 to your computer and use it in GitHub Desktop.
Save iwagaki/83dba6453037860a49f7 to your computer and use it in GitHub Desktop.
factory method
class ClassA
{
public:
void destroy() const
{
delete this;
}
static ClassA* create()
{
return new ClassA;
}
private:
ClassA() {}
~ClassA() {}
};
int main()
{
ClassA* ptr = ClassA::create();
ptr->destroy();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment