Last active
August 29, 2015 14:02
-
-
Save neanias/3df7b2842347cb969fa0 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
using namespace std; | |
class Rectangle { | |
int width, height; | |
public: | |
Rectangle(int x, int y) : width(x), height(y) {} | |
int area(void) { return width * height; } | |
}; | |
int main() { | |
Rectangle obj(3, 4); | |
Rectangle * foo, * bar, * baz; | |
foo = &obj; | |
bar = new Rectangle(5, 6); | |
baz = new Rectangle[2] { {2, 5}, {3, 6} }; | |
cout << "obj's area: " << obj.area() << endl; | |
cout << "*foo's area: " << foo->area() << endl; | |
cout << "*bar's area: " << bar->area() << endl; | |
cout << "baz[0]'s area:" << baz[0].area() << endl; | |
cout << "baz[1]'s area:" << baz[1].area() << endl; | |
delete bar; | |
delete[] baz; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment