This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' 으로 초기화 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CCar | |
{ | |
class CWheel *pWheels[4]; // inline forward declaration | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CBase | |
{ | |
public: | |
virtual void Print() = 0; // pure virtual, abstract | |
}; | |
class CDerived0 : public CBase | |
{ | |
public: | |
CDerived0() { puts("new0"); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int i = 3; | |
const_cast<int&>(i) = 4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma pack(push) | |
#pragma pack(1) | |
struct SRefTest | |
{ | |
char a; | |
char b; | |
char &r; | |
SRefTest() : a(1), b(2), r(a) {} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CBase { | |
virtual void f() {} | |
}; | |
class CDerieve : public CBase { | |
virtual void f() override {} | |
}; | |
void CastTest() | |
{ | |
// dynamic cast with reference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CCaseA { | |
public: | |
CCaseA() = delete; | |
}; | |
class CCaseB { | |
public: | |
CCaseB() = default; | |
CCaseB & operator =(const CCaseB &) = delete; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CTest { | |
public: | |
~CTest() = default; | |
}; | |
CTest *pTest = nullptr; | |
{ | |
CTest &&rrInt = CTest(); | |
pTest = &rrInt; | |
} // ~CTestwekj() |