













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














Lecture 28
class A : base class access specifier B { member access specifier(s): ... member data and member function(s); ... }
Valid access specifiers include public, private, and protected
public base class (B)
public members protected members private members
derived class (A) public protected inherited but not accessible
class A : public B { // Class A now inherits the members of Class B // with no change in the “access specifier” for } // the inherited members
private base class (B)
public members protected members private members
derived class (A) private private inherited but not accessible
class A : private B { // Class A now inherits the members of Class B // with public and protected members } // “promoted” to private
class Shape { public: int GetColor ( ) ; protected: // so derived classes can access it int color; }; class Two_D : public Shape { // put members specific to 2D shapes here }; class Three_D : public Shape { // put members specific to 3D shapes here };
int main ( )
{
Square mySquare; Cube myCube;
mySquare.getColor ( ); // Square inherits getColor() mySquare.getArea ( ); myCube.getColor ( ); // Cube inherits Docsity.com
void swap (int *a, int *b)
{ int temp; temp = *a; *a = *b; *b = temp; }
void swap (float *c, float *d)
{ float temp; temp = *c; *c = *d; *d = temp; }
void swap (char *p, char *q)
{ char temp; temp = *p; *p = *q; *q = temp; }
template
{
T temp; temp = *a; *a = *b; *b = temp;
}
T is a “dummy” type that will be filled in by the compiler as needed
a and b are of “type” T temp is of “type” T swap is a function template, NOT a function
int a = 5, b = 6; float c = 7.6, d = 9.8; char e = 'M', f = 'Z'; swap (&a, &b); // compiler puts int in for T swap (&c, &d); // compiler puts float in for T swap (&e, &f); // compiler puts char in for T Docsity.com