250x250
Notice
Recent Posts
«   2024/07   »
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
관리 메뉴

일상 코딩

[C++/8.1] 객체지향 프로그래밍과 클래스 본문

C++/따배C++ 08강 객체지향 기초

[C++/8.1] 객체지향 프로그래밍과 클래스

polarcompass 2021. 10. 20. 02:44
728x90
#include<iostream>
#include<string>
#include<vector>

using namespace std;

// Object(객체) - 코드로 구현한 단어를 class라 부른다.
//
class Friend{
//sturct는 아 코드가 안들감.
public: // access specifier (public, private, protected(상속 단원))
    string m_name;
    string m_address;
    int m_age;
    double m_height;
    double m_weight;
    
    void print(){
        cout << m_name << " " ;
        cout << m_address << " ";
        cout << m_age << " ";
        cout << m_height << " ";
        cout << m_weight << " ";
    }
};

int main(int argc, char const *argv[])
{
    Friend jj{ "Jack Jack", "Uptown", 2, 30, 10}; // instanciation (메모리를 차지하는 것), instance
    jj.print();
    cout << &jj << endl;

    vector<Friend>  my_friends;
    my_friends.resize(2);

    for(auto &ele : my_friends)
        ele.print();
        cout << endl;

    return 0;
}
728x90