Skip to content

Instantly share code, notes, and snippets.

View fortheday's full-sized avatar
🤩

magicpotato fortheday

🤩
View GitHub Profile
int *i1 = new int; // 초기화안됨
int *i2 = new int();// 됨
int i3 = int(); // 됨
int i4(0); // 됨
int i5{0}; // 됨
int i6(); // 컴파일에러
cout << *i1 << ' ' << *i2 << ' '<< i3 << ' ' << i4 << ' ' << i5 << endl;
char *pArr1 = new char[10]; // 초기화안함
char *pArr2 = new char[10](); // '\0' 으로 초기화
class CCar
{
class CWheel *pWheels[4]; // inline forward declaration
};
class CBase
{
public:
virtual void Print() = 0; // pure virtual, abstract
};
class CDerived0 : public CBase
{
public:
CDerived0() { puts("new0"); }
const int i = 3;
const_cast<int&>(i) = 4;
int add(int a, int b) { return a + b; }
void FuncRefTest()
{
int(*pfnAdd)(int a, int b) = add;
pfnAdd(1, 2);
(*pfnAdd)(1, 2);
pfnAdd = add; // ok
int(&rfnAdd)(int a, int b) = add;
#pragma pack(push)
#pragma pack(1)
struct SRefTest
{
char a;
char b;
char &r;
SRefTest() : a(1), b(2), r(a) {}
};
class CBase {
virtual void f() {}
};
class CDerieve : public CBase {
virtual void f() override {}
};
void CastTest()
{
// dynamic cast with reference
int a = 1, b = 2;
[&] // capture local variables as &a, &b
{
a = 3; // &a = 3
b = 4;
}(); // instant execution
[=] // capture local variables const a, const b
{
class CCaseA {
public:
CCaseA() = delete;
};
class CCaseB {
public:
CCaseB() = default;
CCaseB & operator =(const CCaseB &) = delete;
};
class CTest {
public:
~CTest() = default;
};
CTest *pTest = nullptr;
{
CTest &&rrInt = CTest();
pTest = &rrInt;
} // ~CTestwekj()