Last active
October 21, 2015 15:48
-
-
Save goyusia/f2acbc34e22c14f06093 to your computer and use it in GitHub Desktop.
partial class in C++ (voodoo magic)
This file contains hidden or 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
| /* | |
| Partial class in C++ | |
| This is voodoo magic. DO NOT USE IN YOUR CODE. | |
| $ make run | |
| ## output | |
| ctor | |
| foo : 1 | |
| bar : 2 | |
| dtor | |
| */ | |
| #include "sample.h" | |
| int main() | |
| { | |
| Sample sample; | |
| sample.foo(); | |
| sample.bar(); | |
| return 0; | |
| } |
This file contains hidden or 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
| CXX = clang++ | |
| CXX_FLAGS = -W -Wall -std=c++11 | |
| all: sample.o partial_a.o partial_b.o main.o | |
| clang++ $^ -o a.out $(CXX_FLAGS) | |
| run: all | |
| ./a.out | |
| sample.o: sample.cpp | |
| $(CXX) -c $^ $(CXX_FLAGS) | |
| partial_a.o: partial_a.cpp | |
| $(CXX) -c $^ $(CXX_FLAGS) | |
| partial_b.o: partial_b.cpp | |
| $(CXX) -c $^ $(CXX_FLAGS) | |
| main.o: main.cpp | |
| $(CXX) -c $^ $(CXX_FLAGS) | |
| clean: | |
| rm -rf *.o | |
| rm -rf a.out |
This file contains hidden or 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
| #include "sample.h" | |
| #include <cstdio> | |
| void Sample::foo() | |
| { | |
| printf("foo : %d\n", foo_); | |
| } |
This file contains hidden or 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
| // sample :: partial | |
| public: | |
| void foo(); | |
| private: | |
| const int foo_ = 1; |
This file contains hidden or 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
| #include "sample.h" | |
| #include <cstdio> | |
| void Sample::bar() | |
| { | |
| printf("bar : %d\n", bar_); | |
| } |
This file contains hidden or 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
| public: | |
| void bar(); | |
| private: | |
| const int bar_ = 2; |
This file contains hidden or 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
| #include "sample.h" | |
| #include <cstdio> | |
| Sample::Sample() | |
| { | |
| printf("ctor\n"); | |
| } | |
| Sample::~Sample() | |
| { | |
| printf("dtor\n"); | |
| } |
This file contains hidden or 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 Sample { | |
| public: | |
| Sample(); | |
| ~Sample(); | |
| #include "partial_a.h" | |
| #include "partial_b.h" | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment