Modern C++ Course [Lecture 2] {Compilation, Debugging, Functions, Header/Source, Libraries, CMake}

本文深入探讨了C++编程中的关键概念,包括如何避免内存错误如segmentation fault,利用引用提高效率,以及标准库中vector的常用操作。同时,文章强调了编译警告的重要性,并介绍了不同级别的代码优化选项。此外,还提到了现代C++工作流程中的编译与链接过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.ipb.uni-bonn.de/wp-content/uploads/2018/05/lecture_2.pdf

 


 

 

 

 make bash file executable

 

 

 

 

 

 Wall: Warning all

Wextra: add even more extra Warning

Werror: treat Warnings as errors

 

 

 

 

by default, there's no optimization.

 

-O0

-O3 -Ofaster 

 

 

 

 

 

 

"segmentation fault" means you are using some unallowed memory.

 

 

 

 

 

 

 

use reference to avoid copy, and save a lot time!

 

 explaining how reference as function variable works.

 

 

 

 

 

Announce default variables only in declaration (typo above...).

 

 

sort, sumation, multiplication standard operation in std::vector

 

 

 

 

 

 every header file should include "#pragma once", otherwise you would get wierd errors.

 

 

 

 

 

the compiler doesn't know the definition of the test.cpp.

 

 

simply add the 2nd line will make the "c++ main.cpp ... " work, but no output!

 

build the test.cpp first, and include the result .o file into main.cpp building.

 

     c++ workflow!!!

 

.o file is binary and only machine can read it.

 

 

 

 

 

 

 

  maybe there's a branch of changing now in makefile. but this file is simple and readable.

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/ecoflex/p/10182982.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值