코락 CoRock
코딩하는 락스타
코락 CoRock
  • 분류 전체보기 (393)
    • frameworks (19)
      • spring (19)
      • spring-boot (0)
      • testing (0)
    • languages (94)
      • java (39)
      • kotlin (0)
      • python (42)
      • r (13)
    • libraries (0)
    • programming (239)
      • android (13)
      • c (17)
      • cpp (22)
      • database (18)
      • design-pattern (4)
      • data-structures (11)
      • git (8)
      • hadoop (6)
      • html-css (7)
      • issue (4)
      • javascript (26)
      • jsp (34)
      • os (29)
      • php (6)
      • preferences (19)
      • etc (15)
    • discography (37)
      • k-pop (18)
      • pop (19)
    • blog (3)

블로그 메뉴

  • Programming
  • Java
  • JavaScript
  • Discography
  • K-Pop Songs
  • Pop Songs
  • Blog
  • Guestbook

공지사항

인기 글

태그

  • CentOS
  • Android
  • oracle
  • Spring
  • python
  • linux
  • 파이썬
  • jsp
  • r
  • Java
  • 자바스크립트
  • javascript

최근 댓글

최근 글

티스토리

반응형
hELLO · Designed By 정상우.
코락 CoRock

코딩하는 락스타

[C++] Class Relationship
programming/cpp

[C++] Class Relationship

2018. 3. 8. 13:55
반응형



Class Relationship

1. has ~ a (Data와 관리 class) -> ''문법적으로 포함 오브젝트(embedded object)''를 쓴다


2. is ~ a (상속 구조) -> ''문법적으로 상속


VS 06


Program 04.   Has-a 관계로 구현한 기본



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
using namespace std;
 
class PersonName {
    string name;
public:
    void setName(string name)
    {
        this->name = name;
    }
    string getName() const
    {
        return name;
    }
};
 
class PersonData {
    PersonName pn;
    int age;
public:
    void setName(string name)
    {
        pn.setName(name);
    }
    void setAge(int age)
    {
        this->age = age;
    }
    string getName() const
    {
        return pn.getName();
    }
    int getAge() const
    {
        return age;
    }
};
 
void main()
{
    PersonData pd;
 
    pd.setName("CoRock");
    pd.setAge(15);
 
    cout << pd.getName() << endl;
    cout << pd.getAge() << endl;
}
cs

반응형
저작자표시 비영리 변경금지 (새창열림)
    'programming/cpp' 카테고리의 다른 글
    • [C++] 클래스 상속
    • [C++] Has-a 관계로 구현한 성적관리프로그램
    • [C++] static, const
    • this
    코락 CoRock
    코락 CoRock
    A COder dreaming of being a ROCKstar

    티스토리툴바