0 引言

C++语言特性记录,提高对这门语言的理解,进而带动对编程语言特性的理解。

相关网站及教程

# W3Cschool C++教程
https://www.w3cschool.cn/cpp/ # W3Cschool C语言教程
https://www.w3cschool.cn/c/ # C++ API reference
http://www.cplusplus.com/reference/
http://en.cppreference.com/w/ # geeksforgeeks上的c++ 教程等
https://www.geeksforgeeks.org/c-plus-plus/

1 C++中的const 引用参数

在C++中,很多时候不希望函数调用时使用值传递(这样做需要得到实参的一个拷贝,降低了效率),而使用引用参数(引用本质上就是指针)。由于对引用参数值的改变就是对实参值的改变,有时候不希望改变实参的值,为了防止出错,而使用const 引用参数。这样既有引用参数的效率,而又不会改变实参的值。举个opencv中的例子。

CV_EXPORTS void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
const Mat& img2, const vector<KeyPoint>& keypoints2,
const vector<DMatch>& matches1to2, Mat& outImg,
const Scalar& matchColor=Scalar::all(-), const Scalar& singlePointColor=Scalar::all(-),
const vector<char>& matchesMask=vector<char>(), int flags=DrawMatchesFlags::DEFAULT );

该函数将传入的函数参数用const + 引用的形式传入,将输出参数用引用的形式输出,提高了数据传输效率的同时,保证了实参的安全。

2 ofstream

ios::app:  append,只能在文件末尾插入,对数据的保护性更好。

ios::ate, at end,打开文件的时候程序把光标指向末尾,但是可以任意移动(seek等操作),灵活性更高。

3 STL

(1)std::pair

// pair::pair example
#include <utility> // std::pair, std::make_pair
#include <string> // std::string
#include <iostream> // std::cout int main () {
std::pair <std::string,double> product1; // default constructor
std::pair <std::string,double> product2 ("tomatoes",2.30); // value init
std::pair <std::string,double> product3 (product2); // copy constructor product1 = std::make_pair(std::string("lightbulbs"),0.99); // using make_pair (move) product2.first = "shoes"; // the type of first is string
product2.second = 39.90; // the type of second is double std::cout << "The price of " << product1.first << " is $" << product1.second << '\n';
std::cout << "The price of " << product2.first << " is $" << product2.second << '\n';
std::cout << "The price of " << product3.first << " is $" << product3.second << '\n';
return ;
}

(2)

4 google开源项目风格指南-C++版本

https://zh-google-styleguide.readthedocs.io/en/latest/google-cpp-styleguide/headers/

(1)

5 C++ 类

(1)拷贝构造函数:是指一类以类对象为参数的函数,其作用是复制类对象的成员。

https://www.cnblogs.com/alantu2018/p/8459250.html

最新文章

  1. codeforces Magnets
  2. Redis使用总结之与Memcached异同
  3. iOS项目工作空间搭建
  4. 心情记录&amp;考试总结 3.30
  5. ASP.NET MVC3细嚼慢咽---(2)模板页
  6. Extjs 4.x 得到form CheckBox的值
  7. vim 设定一个新的snippets
  8. Android 实现ActionBar定制
  9. Linux多线程编程——线程的创建与退出
  10. ruby中printf &quot;%x&quot;%-4为何会打印开头..
  11. Go:学习笔记兼吐槽(1)
  12. Arduino-常用指令
  13. 作为一个.NET开发者,怎么看待和选择层出不穷的新技术,新架构?
  14. spring-data-mongo的MongoTemplate开发
  15. Docker-常用命令(7)
  16. OOM
  17. ROS进阶学习笔记(11)- Turtlebot Navigation and SLAM - ROSMapModify - ROS地图修改
  18. Confluence 6 使用 LDAP 授权连接一个内部目录概述
  19. R 画structure图
  20. 使用TortoiseGit+码云管理项目代码

热门文章

  1. SQL group by分组查询
  2. java 随机读写访问流及seek方法
  3. LintCode之删除链表中的元素
  4. Java 系书籍,,,,,,,,,,,,,
  5. node js 操作redis promise
  6. SQL:REGEXP
  7. DB-概念-数据库:数据库/Database
  8. c++primer,自定义一个复数类
  9. spring data jpa 使用方法命名规则查询
  10. htmlspecialchars_decode 解决掉 &amp;amp;