2017년 5월 4일 목요일

[Tips for HW# 6] Code for homework 6!!

Some students ask me a question related to homework 6..
Let me give you some tips ....
Try it and figure it out!!

// From Lecture notes : Inheritance part 1
// Title: [Implementing inheritance] - part 1: basics of inheritance
// pages 13 ~ 14 ..

#include <iostream>

using namespace std;

class A {

protected:
int i;
int j;

public:
A(int tempi, int tempj) {
i = tempi;
j = tempj;
}
};

// A possible way that passes parameters to the base class A
class aa : public A {

protected:
int k;

public:
aa(int aatempi, int aatempj, int aatempk) : A(aatempi, aatempj) {
k = aatempk;
}

void displayaa() {

cout << "i: " << i << endl;
cout << "j: " << j << endl;
cout << "k: " << k << endl;
}

};


int main()
{

aa myaa(2, 3, 5);

myaa.displayaa();

return 0;
}