C++
-
[Effective Modern C++] std::move와 std::forward (2)C++/Effective Modern C++ 2022. 7. 25. 11:16
이전 글 (std::move와 std::forward)에서 std::move와 std::forward에 대하여 알아보았습니다. 이동 시맨틱에서 이동 및 전달을 보조해주는 함수들로, 이름과는 달리 상황에 따른 R-value 캐스팅을 수행합니다. 이전 글에서 각각의 함수의 수행 기능, 의의를 살펴보았다면 이번 글에서는 각각의 함수를 사용하는 상황에 대한 예시를 몇 가지 살펴보도록 하겠습니다. 1. R-value reference에는 std::move 더보기 특정 매개변수가 R-value 참조라면, 그 참조에 묶인 객체는 반드시 이동할 수 있습니다. class MyClass { MyClass(MyClass&& rhs); ... }; 위와 같이, 함수가 객체의 R-value성질을 활용할 수 있어야 하는 경우, ..
-
[Effective Modern C++] R-value reference와 Universal referenceC++/Effective Modern C++ 2022. 7. 13. 22:24
R-value reference는 표기할 때 &&로 표기합니다. 형식 T에 대한 R-value reference는 T&&이 되는 것 입니다. 그러나 T&&이 항상 R-value reference가 되지는 않습니다. 이번 글에서는 그러한 예외에 대하여 살펴보도록 하겠습니다. 1. Universal reference 더보기 void function_1(MyClass&& param); MyClass&& var_1 = MyClass(); auto&& var_2 = var_1; template void function_2(std::vector&& param); template void function_3(T&& param); 위 다섯가지 코드에서, 각각의 &&가 의미하는 것은 다음과 같습니다. function_1..
-
[Effective Modern C++] std::move와 std::forwardC++/Effective Modern C++ 2022. 6. 30. 14:02
C++11에 제안된 이동 시맨틱(Move semantics)은 이동 생성자와 이동 배정 연산자를 사용합니다. 위 함수들을 사용함으로써 복사 연산을 이동 연산으로 대체하는 것에 의의가 있으며, 이것은 함수의 비용이 줄어든다는 장점을 가지고 있습니다. 또한 복사 연산을 제한하는 객체 (std::unique_ptr과 같은)를 이동 연산으로 이동할 수 있다는 특징이 있습니다. 이번 글에서는 이동 시맨틱에 사용되는 함수들인 std::move와 std::forward에 대해 살펴볼 것 입니다. 1. 개요 더보기 std::move와 std::forward는 각각 이동, 전달이라는 의미를 가진 함수입니다. 하지만, 이들 함수가 실제로 이동과 전달을 수행하지는 않습니다. 이들 함수를 사용한 코드의 결과를 보면 이동과 전..
-
[WinAPI] Edit Control에서 Enter키 입력 받기C++/미분류 2022. 6. 22. 12:39
WinAPI의 Edit control은 사용자의 입력을 받는 컨트롤 중 하나입니다. 때때로는 설계 방식에 따라, 이 입력 도중 Enter키를 통해 특정 상호작용을 해야 할 때가 있습니다. 이번 글에서는 그에 대해 다루어 보도록 하겠습니다. 1. UI 설정 더보기 글에서 목표하는 바는 Edit control에서 Enter키가 개행 이외의 방법으로 작동 되게 하는 것 입니다. 이를 위해 간단하게 Edit Control이 있는 UI를 만들어 보도록 하겠습니다. 코드 및 형태는 아래와 같습니다. #include #include #include #include #include #define ID_EDIT 100 static TCHAR szWindowClass[] = _T("DesktopApp"); static T..
-
[Visual Studio] LNK2019, LNK1120C++/미분류 2022. 6. 13. 14:35
LNK2019 : main"int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 함수에서 참조되는 확인할 수 없는 외부 기호 LNK1120 : 1개의 확인할 수 없는 외부 참조입니다. 위 메시지는 프로그램의 진입점을 찾지 못해서, 혹은 설정이 잘못되어서 출력되는 메시지 입니다. 발생 원인은 여러가지가 존재하겠지만, 제가 겪어본 사례들과 해결 방법을 나열해보도록 하겠습니다. 1. 프로젝트 구성 형식 변경 더보기 프로젝트 속성 페이지 (프로젝트 우클릭 -> 속성)에서 구성 형식을 변경합니다. CUI, GUI의 경우에는 애플리케이션으로 설정할 수 있습니다. main함수가 필요하지 않은 라이브러리 (.lib, .dll)의 경우는 각각 상황에 맞게 설정할 수 있습니다. 2..
-
[Visual Studio] Solution & ProjectC++/미분류 2022. 6. 7. 18:04
프로젝트(Project)는 일반적으로 하나의 실행 파일, 혹은 그에 준하는 무언가(라이브러리 등)의 결과를 산출합니다. 하지만, 이것이 특정 문제의 "해답"이라고 볼 수 없거나, 한 개의 프로젝트로 묶기에는 연관성이 떨어지는 경우가 존재합니다. 예를 들어, 특정 라이브러리를 만든다거나, 서버와 클라이언트로 나뉘어있는 경우가 그럴 수 있습니다. Visual Studio, 그리고 대부분의 IDE는 이러한 상황을 능동적으로 다룰 수 있는 기능이 있습니다. 이번 글에서는 이에 관해 다루어 보도록 하겠습니다. 1. 솔루션과 프로젝트 만들기 및 추가 더보기 솔루션은 프로젝트들을 담을 수 있는 컨테이너 입니다. 프로젝트가 모여서 솔루션이 된다고 생각해도 무방할 것 같습니다. Visual Studio는 처음 프로젝트를..
-
[Effective Modern C++] Pimpl idiomC++/Effective Modern C++ 2022. 6. 1. 16:17
Pimpl 관용구 (Pimpl idiom)은 빌드 최적화 및 클라이언트 의존성 해소를 위한 디자인 패턴 입니다. 이번 글에서는 Pimpl에 대한 기본적인 구현 방식을 살펴보도록 하겠습니다. 1. Pimpl 더보기 Pimpl의 기본적인 구현 방식은 자료 멤버들을 특정 객체로 대체하고, 그 특정 객체를 포인터를 통해 간접적으로 접근하는 것 입니다. 예제를 살펴보도록 하겠습니다. class MyClass { public: MyClass(); ... private: std::string name; std::vector data; Object obj_1, obj_2; // Custom class }; 위와 같이 정의된 클래스가 있을 경우, 클라이언트는 , , object.h를 포함해야 합니다. 그리고 이것은 컴파..
-
[Effective Modern C++] Smart pointer : std::make_unique<>, std::make_shared<>C++/Effective Modern C++ 2022. 5. 25. 12:03
이전 글에서 스마트 포인터 중 std::unique_ptr, std::shared_ptr, std::weak_ptr에 대하여 살펴보았습니다. 스마트 포인터를 생성할 때에는 Raw pointer와 유사하게 new연산자를 사용하는 방법이 있고, 표준 라이브러리에 존재하는 std::make_unique, std::make_shared와 같은 함수를 사용하는 방법이 있습니다. 생성하는 방법은 두 가지지만, 특정 경우를 제외할 경우 new연산자 보다는 make함수를 사용하는 것이 권장됩니다. 이번 글에서는 두 종류의 make함수와 이것이 new와 비교하여 가지는 장점이 무엇인지 살펴보도록 하겠습니다. 1. 코드 중복 (Duplicate) 더보기 make함수들의 장점으로 보일 수 있는 가장 간단한 예시는 아래 예제..