Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active August 29, 2015 14:10
Show Gist options
  • Save icholy/00f37eec4fccb101d13b to your computer and use it in GitHub Desktop.
Save icholy/00f37eec4fccb101d13b to your computer and use it in GitHub Desktop.
// 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