Visual Studio
C++ 재활 본문
한동안 너무 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());
'Programming Language' 카테고리의 다른 글
memset의 함정 (은근 착각하기 쉬움) (0) | 2022.06.19 |
---|---|
가상함수, RTTI (0) | 2022.06.14 |
Virtual Function in C++ (0) | 2022.03.04 |
[C/C++] 가변인자 매크로로 함수 호출시 불필요한 쉼표 생략하는법 (0) | 2021.11.22 |
C에서 객체지향 프로그래밍을 하는 방법 - GObject (0) | 2021.11.22 |