Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- class Kotak {
- public:
- Kotak(int id) : _id(id) {
- printf("[%d] constructor\n", _id);
- }
- ~Kotak() {
- printf("[%d] destructor\n", _id);
- }
- void siapa() {
- printf("[%d] ini kotak\n", _id);
- }
- private:
- int _id;
- };
- int main() {
- Kotak a(1);
- a.siapa();
- {
- Kotak b(2);
- }
- Kotak c(3);
- c.siapa();
- Kotak *d = new Kotak(4);
- d->siapa();
- delete d;
- {
- Kotak e(5);
- d = &e;
- d->siapa();
- }
- d->siapa();
- }
- /* output:
- [1] constructor
- [1] ini kotak
- [2] constructor
- [2] destructor
- [3] constructor
- [3] ini kotak
- [4] constructor
- [4] ini kotak
- [4] destructor
- [5] constructor
- [5] ini kotak
- [5] destructor
- [5] ini kotak
- [3] destructor
- [1] destructor
- */
Add Comment
Please, Sign In to add comment