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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string.h>
using namespace std;
 
 
class Human {
public:
    int age;
    char name[20];
    char gender[10];
 
    Human() {
        age = 0;
        memset(name, 0sizeof(char* 20);
        memset(gender, 0sizeof(char* 10);
    }
    void setAge(int age) { this->age = age; }
    void setName(char* name) { strcpy(this->name, name); }
    void setGender(char* gender) { strcpy(this->gender, gender); }
 
 
    void printAll() {
        cout << age << name << gender;
    }
};
 
class jina : public Human {
    char address[20];
public:
    jina(int age, char* name, char* gender, char* address) {
        setAge(age);
        setName(name);
        setGender(gender);
        strcpy(this->address, address);
    }
    void printAll() {
        cout << address << age << name << gender;
    }
};
 
int main() {
    const int* a = new int(10);
    int* b = const_cast<int*>(a);
    *= 100;
    cout << *<< endl;
 
    /*
        자식의 크기가 더크지. 자식을 잘라서 부모로 맞추는건 가능, 부모를 키워서 자식으로 하는건 불가능
    */
 
    jina* ja = new jina(24"jIN""여자""자양동");
    Human* pja = new Human;
    pja = dynamic_cast<Human*>(ja);
    
    ja->printAll();
    pja->printAll();
 
    jina* temp = new jina(24"아진""남자""오우동");
    Human* temp2 = new Human();
    //temp = dynamic_cast<jina*>(temp2); 안됨
    //temp = static_cast<jina*>(temp2); 되긴되는데 제대로 출력안됨
    
    int* c = reinterpret_cast<int*>(temp2); //안되는거 같음
    
    cout << c<<",";
    cout << *c;
 
 
 
    return 0;
}
cs

업캐스팅, 다운캐스팅 dynamic , reinterpret ,constcast에 관해 실험해봤는데,


상수화를 풀어주는 const만 쓸만한 것 같다.

'잡동사니' 카테고리의 다른 글

마지막 팀프  (0) 2018.06.24
팀프3  (0) 2018.06.24
팀프1-2  (0) 2018.06.24
팀프1  (0) 2018.06.24
C# Astar  (0) 2018.05.26

+ Recent posts