Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Visual Studio

C++ 재활 본문

Programming Language

C++ 재활

emacser 2022. 4. 6. 01:28

한동안 너무 C++를 안써서 기억이 가물가물하다.

사용하면서 기억해둘만한 것들이나 까먹기 쉬운 것을 메모한다.

 

singleton example code

https://github.com/ReolSt/GLEngine/blob/main/GL/core/Singleton.h

예전에 opengl 기반 엔진 만들때 썼던 싱글턴 클래스이다.

"어떻게 쓰는데요?"
// in YourClass.h

class YourClass : public Singleton<YourClass>
{
	원하는 대로 하세요...
};

// in main.cpp

int main()
{
	...
    
    auto instance = YourClass::GetInstance();
    
    ...
}

 

static member function definition outside of header file

 

definition of static class function outside of class definition

Consider the followin simple class definition - // file A.h #include <iostream> class A { public: static int f(); static const int aa; }; // file A.cpp #include "a.h" using name...

stackoverflow.com

 

Why can a static member function only be declared static inside the class definition and not also in its own definition?

While implementing a class for creating/updating boxes on the screen, I wanted to add a static member function that makes sure no currently visible boxes overlap (taking its information from a static

stackoverflow.com

 두번째 글에 따르면 virtual, inline, static member function은 헤더 파일의 class definition에서만 정의할 수 있다.

 

creating GUID in windows

 

CoCreateGuid function (combaseapi.h) - Win32 apps

Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.

docs.microsoft.com

combaseapi.h에 정의되어있는 CoCreateGuid로 GUID 타입의 guid를 얻을 수 있다. CoCreateGuid는 HRESULT를 리턴하고 인자로 GUID의 포인터를 받는다. guid를 저장할 개체의 포인터를 넘겨주면 된다.

 

How to convert guid to *char

I would like to convert a CLSID to a *char in c++ so I can display it in a text box. I am new to c++ so please make this as simple a s possible. Thanks

stackoverflow.com

위 링크의 방법으로 GUID에서 std::string으로 변환할 수 있다.

 

casting

upcasting / downcasting

 

static_cast

 

dynamic_cast

 

const_cast

 

reinterpret_cast

 

static_pointer_cast, dynamic_pointer_cast, const_pointer_cast, reinterpret_pointer_cast

 

std::string to std::wstring

std::string str = "Test String";
std::wstring wstr;

wstr.assign(str.begin(), str.end());

std::wstring to std::string

std::wstring wstr = L"Test String";
std::string str;

str.assign(wstr.begin(), wstr.end());