Created
February 19, 2015 16:22
-
-
Save iwagaki/83dba6453037860a49f7 to your computer and use it in GitHub Desktop.
factory method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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