-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//01-Minimal | ||
|
||
int main(){} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//02-Constant | ||
//immutability. | ||
//const: run time constant. | ||
//constexpr: compile time constant. | ||
|
||
int x = 1; | ||
const int y = x; | ||
//constexpr int z = x; //error. | ||
|
||
|
||
//double f(double x){return x*x;} | ||
constexpr double f(double x){return x*x;} | ||
constexpr int z = f(10); | ||
|
||
|
||
int main(){} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//03-Enum | ||
|
||
//plain enum. | ||
enum COLOR{Red, Green, Blue}; | ||
int C = COLOR::Red; //Red. | ||
|
||
//strongly typed enum. | ||
enum class color{Red, Green, Blue}; | ||
//int c = color::Red; //error. | ||
//color c = 1; //error. | ||
color c = color::Red; | ||
|
||
int main(){} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//04-Modularity | ||
//declaration and implementation are seperated into different files. | ||
|
||
//class.h | ||
class C{ | ||
int x; | ||
void f(int); | ||
}; | ||
|
||
//class.cpp | ||
//#include "class.h" | ||
void C::f(int y){ | ||
x = y; | ||
} | ||
|
||
//main.cpp | ||
//#include "class.h" | ||
int main(){} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//05-Namespace | ||
//used to organize components. | ||
|
||
namespace N{ | ||
void f(){} //N namespace. | ||
}; | ||
|
||
void f(){} //global scope. | ||
|
||
int main(){ | ||
//using namespace N; //error. conflict. | ||
N::f(); | ||
f(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//06-Exception | ||
//report errors found at run time. | ||
|
||
#include <iostream> | ||
|
||
class C{ | ||
public: | ||
C(int x){ | ||
if(x > 10) throw std::out_of_range{"Exception: Large Number."}; | ||
} | ||
}; | ||
|
||
int main(){ | ||
try{ | ||
C c{15}; | ||
} | ||
catch(std::out_of_range){ | ||
std::cout << "Exception occured.\n"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//07-StaticAssertion | ||
//compile time error checking. | ||
|
||
#include <iostream> | ||
|
||
int main(){ | ||
const int x = 15; | ||
static_assert(x<10, "integer is too large."); //error at compile time. | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//08-InitializerList | ||
|
||
#include <iostream> | ||
|
||
class C{ | ||
public: | ||
C(std::initializer_list<int> l){ | ||
data = new int[l.size()]; | ||
std::copy(l.begin(), l.end(), data); | ||
} | ||
|
||
int *data; | ||
}; | ||
|
||
int main(){ | ||
C c{1, 2, 3}; | ||
std::cout << c.data[0] << std::endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*** MODERN CPP *** |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*** MODERN CPP *** | ||
|
||
[SOFTWARE] | ||
* Compiler: MinGW GCC, MSVC | ||
* IDE: CodeLite, Visual Studio 2019 | ||
|
||
01-Empty | ||
02-Constant | ||
03-Enum | ||
04-Seperation | ||
05-Namespace | ||
06-Exception | ||
07-StaticAssertion | ||
08-InitializerList |