Skip to content

Instantly share code, notes, and snippets.

@neanias
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neanias/3df7b2842347cb969fa0 to your computer and use it in GitHub Desktop.
Save neanias/3df7b2842347cb969fa0 to your computer and use it in GitHub Desktop.
#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