随笔分类 - C++
基础
摘要:友元是为了让 全局函数作友元 #include<iostream> #include<string> using namespace std; class Student { public: int age; private: int height; public: Student(int age1
阅读全文
摘要:当一个类的成员是一个对象时,他先构造内部的对象,析构时是相反的顺序。 #include<iostream> #include<string> using namespace std; class Student { private: int age; int height; public: Stud
阅读全文
摘要:括号法 就是直接用普通函数的调用方式 #include<iostream> #include<string> using namespace std; class Student { private: int age; int *height; public: Student(int age1, i
阅读全文
摘要:如果类中的某个属性是指针,且该指针指向的是一个堆 当创建一个新的类,而且拷贝构造函数默认时或者是直接的赋值,那两个类的该属性就指向同一个地址,当在析构函数中加入删除堆的操作时,会报错 #include<iostream> #include<string> using namespace std; c
阅读全文
摘要:当只设置了有参构造函数时,编译器会默认不再有无参构造函数和析构函数,但是有拷贝构造函数 #include<iostream> #include<string> using namespace std; class Student { private: int age; public: Student
阅读全文

浙公网安备 33010602011771号