CMPT 212
Fall 1997
|
// shape.h class rectangle { public: void setSize(int x, int y); int getWidth(); int getLength(); private: int width; int length; }; // <-- Note the semicolon. // main.cpp #include#include "shape.h" int main() { rectangle a; rectangle * b = NULL; a.setSize(5, 12); cout << a.getWidth(); b = new rectangle; (*b).setSize(3,4); // These two lines do b->setSize(3,4); // the same thing. cout << b->getLength(); return 0; }
// shape.cpp #include "shape.h" void rectangle::setSize(int x, int y) { width = x; length = y; } int rectangle::getWidth() { return width; } int rectangle::getLength() { return length; }
// shape.cpp #include "shape.h" int getWidth() { return screenWidth; // Assume screenWidth is previously defined. } int rectangle::getWidth() { return width; } void rectangle::maximizeWidth() { width = ::getWidth(); }
inline int myFunc(char c);
Return to lecture notes index |
|
This page is maintained by simpson@cs.sfu.ca. | Last updated on 6 Oct 1997. |