본문 바로가기

전체 글51

원형큐 원형큐입니다. #pragma once #include #include template class circular_queue{private:/*use modulo operation to check boundso, add one more space in container*/std::array container; public:int front;int rear; circular_queue(): front(0), rear(0), container(){} ~circular_queue(){} void enqueue(t_type element){if(!full()){container[rear] = element;rear = (rear + 1) % container.size();}} t_type dequeue(){if(.. 2018. 6. 9.
RAII RAII (Resource Acquisition is initialization) 은 사용 전에 획득되야하는 자원의 생명주기를 오브젝트의 생명주기에 바인딩하는 기술이다. 쉽게 말하자면 초기화 (사용되기 전) 에서 자원 획득을 해야하며 자원은 초기화단계에서 획득이 되어야한다라고 볼 수 있다. cppreference에는 RAII의 이점을 다음과 같이 설명하고 있다. RAII guarantees that the resource is available to any function that may access the object RAII는 오브젝트에 접근할 수 있는 어떠한 함수에서도 자원이 유효하다는 것을 보장한다. It also guarantees that all resources are released whe.. 2018. 5. 23.
Why is the size of an empty class not zero? 본문 왜 빈 클래스의 사이즈가 0이 아닌가요? 서로 다른 오브젝트의 주소값을 다르게 하기 위해서입니다. 같은 이유로 new 키워드는 항상 다른 오브젝트들의 포인터들을 반환합니다. class Empty { }; void f(){Empty a, b;if (&a == &b) cout 2018. 5. 10.
Why is "this" not a reference? 번역 왜 this는 reference가 아닌가요? 왜냐하면 reference가 추가되기 전에 C++에 도입되었기 때문입니다. 그리고, smalltalk의 self 대신 Simula의 사용법을 따르기 위해 this를 선택했습니다. 원문 Why is "this" not a reference? Because "this" was introduced into C++ (really into C with Classes) before references were added. Also, I chose "this" to follow Simula usage, rather than the (later) Smalltalk use of "self". 2018. 5. 10.