CMPT 212
Fall 1997
|
Read chapter 13 (except sections with Template in the name) from C++ Primer Plus (2nd ed.), by Stephen Prata. |
class animal { ... }; class mammal : public animal { ... }; class egg_layer : public animal { ... }; class platypus : public animal, public egg_layer { ... }:
class Point { public: Point() { x_coord = 0.0; y_coord = 0.0; } Point(float x, float y) { x_coord = x; y_coord = y; } ... private: float x_coord; float y_coord; }; class Circle : public Point { public: Circle(); Circle(float x, float y, float r); ... private: float radius; }; Circle::Circle() { radius = 0.0; } Circle::Circle(float x, float y, float r) : Point(x, y), radius(r) { }We could also use initialization lists for the two Point constructors and the default Circle constructor.
class baseClass { public: int a; private: int b; }; class derivedClass { public: int c; private: int d; };In an instance of derivedClass, the members a and c are publicly accessible, and b and d are not.
Access in base class | Base class inherited as | Access in derived class |
---|---|---|
public protected private |
public |
public protected no access |
public protected private |
protected |
protected protected no access |
public protected private |
private |
private private no access |
Return to lecture notes index |
|
This page is maintained by simpson@cs.sfu.ca. | Last updated on 13 Nov 1997. |