Week 08 - Constructors, Class Hierarchy, Design

Cc public private protected access specifiers public

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rson& p) Example: person.cc Public, Private, Protected ● Access specifiers ○ public: ○ private: ○ protected: visible to everyone visible to class visible to class and subclasses ● Inheritance ○ http://en.wikibooks. org/wiki/C++_Programming/Classes/Inheritance ● Aside: Why make a constructor protected? ○ Interface (for design purposes) ■ Object cannot be created of this class type ■ Class (and constructor) can be inherited Inheritance Examples class Base { public: int public_int; protected: int protected_int; private: int private_int; }; class A : public Base { // public_int is public // protected_int is protected // private_int is inaccessible }; class B : protected Base { // public_int is protected // protected_int is protected // private_int is inaccessible }; class C : private Base { // public_int is private // protected_int is private // private_int is inaccessible } Inheritance Examples class Base { public: int public_int; protected: int protected_int; pr...
View Full Document

This note was uploaded on 04/05/2013 for the course CS CS 31 taught by Professor Smallberg during the Winter '11 term at UCLA.

Ask a homework question - tutors are online