forked from parallel101/course
-
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
103 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,5 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
set(CMAKE_CXX_STANDARD 17) | ||
project(hellocpp LANGUAGES CXX) | ||
|
||
add_executable(cpptest main.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,25 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
struct C { | ||
C() { | ||
printf("分配内存!\n"); | ||
} | ||
|
||
~C() { | ||
printf("释放内存!\n"); | ||
} | ||
}; | ||
|
||
int main() { | ||
C *p = new C; | ||
|
||
if (rand() != 0) { | ||
printf("出了点小状况……\n"); | ||
// delete p; // 程序员粗心忘记释放指针 | ||
return 1; | ||
} | ||
|
||
delete p; | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set -e | ||
|
||
cmake -B build | ||
cmake --build build | ||
build/cpptest |
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,5 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
set(CMAKE_CXX_STANDARD 17) | ||
project(hellocpp LANGUAGES CXX) | ||
|
||
add_executable(cpptest main.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,24 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <vector> | ||
|
||
struct C { | ||
C() { | ||
printf("分配内存!\n"); | ||
} | ||
|
||
~C() { | ||
printf("释放内存!\n"); | ||
} | ||
}; | ||
|
||
int main() { | ||
std::vector<C> p(1); | ||
|
||
if (rand() != 0) { | ||
printf("出了点小状况……\n"); | ||
return 1; // 自动释放 p | ||
} | ||
|
||
return 0; // 自动释放 p | ||
} |
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,5 @@ | ||
set -e | ||
|
||
cmake -B build | ||
cmake --build build | ||
build/cpptest |
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,5 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
set(CMAKE_CXX_STANDARD 17) | ||
project(hellocpp LANGUAGES CXX) | ||
|
||
add_executable(cpptest main.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,24 @@ | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <vector> | ||
|
||
struct C { | ||
C() { | ||
printf("分配内存!\n"); | ||
} | ||
|
||
~C() { | ||
printf("释放内存!\n"); | ||
} | ||
}; | ||
|
||
int main() { | ||
std::vector<C> p(1); | ||
|
||
if (rand() != 0) { | ||
printf("出了点小状况……\n"); | ||
return 1; // 自动释放 p | ||
} | ||
|
||
return 0; // 自动释放 p | ||
} |
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,5 @@ | ||
set -e | ||
|
||
cmake -B build | ||
cmake --build build | ||
build/cpptest |
Binary file not shown.