본문 바로가기

상속inheritance3

C++ 다형성 가상함수 이해 간단 코드 다형성 virtual 가상함수 #include#includeusing namespace std; class A {public:virtual void f() { cout 2019. 1. 23.
C++ 상속inheritance, (순수)가상함수(pure)virtual function, 추상 클래스(abstract class), overriding, 바인딩 가상 함수 정의 virtual 기본 클래스 멤버 함수의 선언;virtual int computeSalary() { return 1500000; } 가상 함수 구현 Code 예시 #include #include using namespace std; //추상 클래스class Employee{private:string name;int id; public:Employee();Employee(string name, int id);~Employee();void setName(string name);string getName();void setId(int id);int getId(); virtual int computeSalary() { return 1500000; } //가상 함수, 보다 직관적으로 함수를 호출};.. 2019. 1. 18.
C++ 상속inheritance, derived class, 오버라이드(overriding) - Power C++ p565 LAB 상속inheritancederived class 선언class 파생 클래스 명 : 접근 지정자 기본 클래스 명{파생 클래스에 추가할 멤버 선언}; 클래스의 큰 장점인 '상속(inheritance)' '캡슐화(Encapsulation)' '다형성' protected : 파생클래스의 함수에서 기본 클래스의 protected멤버에 접근할 수 있다. 상속방법:class Student : public Human 기본 클래스의 public 멤버 -> 파생 클래스의 public 멤버기본 클래스의 protected멤버 -> 파생 클래스의 protected멤버기본 클래스의 private멤버 -> 파생 클래스의 private멤버 멤버 함수 오버라이드오버라이드(overriding) : 파생 클래스의 함수가 기본 클래스의 함.. 2019. 1. 17.