Last active
August 29, 2015 14:10
-
-
Save icholy/00f37eec4fccb101d13b to your computer and use it in GitHub Desktop.
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
| // in C++ | |
| class Foo { | |
| int a; | |
| int b; | |
| void set_a(int a) { | |
| this->a = a; | |
| } | |
| void set_b(int b) { | |
| this->b = b; | |
| } | |
| void print() { | |
| std::cout << this->a << " " << this->b << std::endl; | |
| } | |
| }; | |
| // in C | |
| typedef struct { | |
| int a; | |
| int b; | |
| } Foo; | |
| void foo_set_a(Foo *this, a) { | |
| this->a = a; | |
| } | |
| void foo_set_b(Foo *this, b) { | |
| this->b = b; | |
| } | |
| void foo_print(Foo *this) { | |
| printf("%d %d", this->a, this->b); | |
| } | |
| int main(void) { | |
| // C++ | |
| Foo foo; | |
| foo.set_a(123); | |
| foo.set_b(123); | |
| foo.print(); | |
| // C | |
| Foo foo; | |
| foo_set_a(&foo, 123); | |
| foo_set_b(&foo, 123); | |
| foo_print(&foo) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment