RSS Feed
Articles
-
8.3 생성자
```c++ class Fraction { private: int m_numerator; // 여기서 초기화값 설정 가능 int m_denominator; public: //생성자 //외부에서 호출하려고 쓰는 것이 아님. 선언과 동시에 실행됨. // 생성자를 안써주면 Fraction(){}과 같이 아무일도 안하는 생성자가 있음! Fraction() { m_numerator = 1; m_denominator = 1; } // 이렇게 파라미터가 없는 생성자를 써주거나 아래처럼 기본값 오버로딩 // 하지만 둘다 쓸 경우 둘 중에 뭘 써야 할지 몰라서 에러 발생
Fraction(const int& num_in=1, const int& den_in=1) { m_numerator = 0; // 반환 데이터 타입 없음. class 이름과 동일하면 생성자(Constructor) m_denominator = 1; } void print() { cout << m_numerator << " / " << m_denominator << "\n"; } }
-
8.2 캡슐화, 접근 지정자, 접근 함수
```c++ #include
#include #include using namespace std; -
8.1 객체지향 프로그래밍과 클래스
우리가 이러한 구조를 하나로 묶어서 표현할 수 있다. -> struct
-
7.16 생략부호 ellipsis
```c++ #include
#include // for ellipsis using namespace std; -
7.14 단언하기 assert
```c++ #include
#include #include using namespace std;