목록class (6)
일상 코딩
#include using namespace std; class Fruit { public: enum FruitType { APPLE, BANANA, CHERRY, }; class InnerClass { }; struct InnerStruct { }; private: FruitType m_type; public: Fruit(FruitType type) : m_type(type) { } FruitType getType() { return m_type; } }; int main() { Fruit apple(Fruit::APPLE); if (apple.getType() == Fruit::APPLE) { cout
1. 익명객체 #include using namespace std; class A { public: int m_value; A(const int &input) : m_value(input) { cout
static은 this-> 포인터 사용 불가. class 내부 함수는 특정 instance에 묶여있지 않다. #include using namespace std; class Something { public: // inner class class _init { public: //inner class 생성자 _init() { s_value = 9876; } }; private: static int s_value; int m_value; static _init s_initializer; public: // 특정 instance 없이도 // s_value에 접근 가능하도록 // 함수 앞에 static을 붙여준다. static int getValue() { //static은 this-> 를 사용하지 못함. re..

static 변수는 cpp 파일에서만 선언한다. #include using namespace std; class Something { public: static int s_value; }; int Something::s_value = 1; // define in cpp file(static 값일 경우.) int main() { cout
함수 인자로 형태로 넣어주면 같은 메모리를 사용하므로 효율이 극대화 된다. #include using namespace std; class Something { public: int m_value = 0; Something(const Something& st_in) { m_value = st_in.m_value; cout
#include #include #include using namespace std; class Date { // 기본이 private으로 설정되어있음. 안적어도 무방함. private: // access specifier int m_month; int m_day; int m_year; public: void setDate(const int& day_input, const int& year_input) { m_day = day_input; m_year = year_input; } void setMonth(const int& month_input) { m_month = month_input; } const int& getDay() // const로 수정을 막아준다. { return m_day; } void..