C++学习备忘录(二)

1、文件读写:  #include <fstream>   文本文件就是ASCii码文件。 二进制文件 

ifstream  读文件  ofstream   写文件   fstream  读写文件

2、函数模板: template <typename T>

void myswap(T &a,T &b) {}  

int a=10;

int b=20;

myswap<int>(a,b);

3、hpp 包含h 和cpp文件。  一般都是类模板的文件。

4、编译器默认为每个类创建默认构造函数、默认析构函数、默认拷贝构造函数、默认赋值函数。(C++ 11)移动构造函数  移动拷贝函数

=delete 类的成员函数不能被访问  =default 无参构造函数依然被构造。  https://blog.csdn.net/whahu1989/article/details/90648536

5、NULL 和nullptr 区别;NULL=0, nullptr表示空指针。https://blog.csdn.net/qq_18108083/article/details/84346655

6、typeid()  返回类型:  char * str="hello world";   typeid(str) 和typeid(char *) 等价   

7、new 关键字:申请内存,调用构造函数,返回对象的指针。

8、using关键字的用法:

using uint=unsigned int;   uint i=1;     

using MapString=map<T,char*>;     MapString<int> numberMap;

 9、当父类中有多个重载函数时,如果一个被子类重写,子类中只能调用该重写函数,不能再调用其他父类重载函数。

https://blog.csdn.net/qq_26399665/article/details/52080215

10、C++ 不支持在函数外返回局部变量的地址,除非定义局部变量为 static变量。

https://www.runoob.com/cplusplus/cpp-return-pointer-from-functions.html

 11、

常对象只能调用常函数,不能调用非常函数(常对象也包括常指针和常引用)  常对象可以调用静态函数

posted @ 2020-10-27 23:28  树下看猴  阅读(102)  评论(0编辑  收藏  举报