일상 코딩
[C++/8.1] 객체지향 프로그래밍과 클래스 본문
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
'C++ > 따배C++ 08강 객체지향 기초' 카테고리의 다른 글
[C++/8.6] CLASS 소멸자, destructor (0) | 2021.10.21 |
---|---|
[C++/8.5] CLASS 위임 생성자, 초기화 함수 이용 (0) | 2021.10.21 |
[C++/8.4] 생성자 멤버 초기화 (0) | 2021.10.21 |
[C++/8.3] 생성자 constructors (0) | 2021.10.20 |
[C++/8.2] 캡슐화, 접근 지정자, 접근함수 (0) | 2021.10.20 |