21-InheritanceAccess

21-InheritanceAccess - / Access Modifiers and Mutliple...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// Access Modifiers and Mutliple Inheritance #include <iostream> using namespace std; class BaseClass { private: int privateInt; protected: int protectedInt; public: int publicInt; BaseClass(int prii = 0, int proi = 0, int pubi = 0) { privateInt = prii; protectedInt = proi; publicInt = pubi; } int getPrivate() { return privateInt; } int getProtected() { return protectedInt; } }; class PublicDerived : public BaseClass { private: int derivedPrivate; // privateInt; // with this inheritance mode it is like // declaring privateInt here protected: int derivedProtected; // protectedInt; public: int derivedPublic; // publicInt; /********************************************************** * Constructors **********************************************************/ PublicDerived(int dpri = 0, int dpro = 0, int dpub = 0) { //this->privateInt = dpri; // cannot access private members of inherited type protectedInt = dpro; derivedPrivate = dpri; derivedProtected = dpro; derivedPublic = dpub; } PublicDerived(int bpri, int bpro, int bpub, int dpri, int dpro = 0, int dpub = 0) : BaseClass(bpri, bpro, bpub) { derivedPrivate = dpri; derivedProtected = dpro; derivedPublic = dpub; } /**********************************************************
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
* Getters **********************************************************/ int getDerPrivate() { return derivedPrivate; } int getDerProtected() { return derivedProtected; } /********************************************************** * Misc **********************************************************/ void attempAccess() { //privateInt = 1; // Cannot access private memeber protectedInt = 1; publicInt = 1; derivedPrivate = 1; // But we can access this private member derivedProtected = 1; derivedPublic = 1; BaseClass obj; //obj.privateInt = 2; //obj.protectedInt = 2; obj.publicInt = 2; } }; class ProtectedDerived : protected BaseClass
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Page1 / 5

21-InheritanceAccess - / Access Modifiers and Mutliple...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online