![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
仰望星空的快乐
加油加油加油加油
展开
-
c和c++的指针
void main() { int * ptr;/*声明一个指针类型的变量,名字叫ptr,指向的是int类型,在声明部分的*号表示声明一个 int类 型的变量,在其他部分就是表示ptr指向的变量的值*/ //&a a不管是普通变量还是指针,都指向的是该变量自己的地址 ptr = new int(5);//在堆中开一个int变量大小的空间,变量的值为5,并让指针ptr指向这个变量; //int a=5; //pt.原创 2021-10-13 19:27:25 · 341 阅读 · 0 评论 -
c++的虚基类
从父类B中继承了两个子类A和C,如果有个类D,想要多继承继承A和C,就会报错,因为在C中生成了两份B的内容,d会不知道访问哪一个。 #include<iostream> #include <string> using namespace std; class B { public: int hhh; B(int a):hhh(a) { cout << "调用了b一个参数的构造函数"<<endl; } }; class C :public B { p原创 2021-11-27 14:16:38 · 409 阅读 · 0 评论 -
c++继承
继承就是拷贝图纸,我有一张轮子的图纸(基类),我要画汽车的图纸(子类),我可以直接把轮子的图纸加到汽车的图纸上,不用再画轮子。这就是继承。 不管public还是protectd还是private在类体内都是不限制访问的 protected和private的属性和方法都不可以类外通过实例来访问protectd表示该类可以继承,private表示该类不可以继承 class Base { public: int pub_mem; protected: int pro_mem; private: .原创 2021-11-26 19:43:19 · 362 阅读 · 0 评论 -
c++的复制运算符和复制构造函数
C++ 拷贝构造函数和赋值运算符 - evilsnake - 博客园 如果那句代码能生成新的对象,就执行拷贝构造函数,如果不能生成新的对象,执行的就是复制赋值构造函数。 #include <iostream> using namespace std; class Person { public: Person() { cout << "执行了无参数的构造函数"<<endl; } Person(const Person& p) { cout &l原创 2021-11-25 20:50:18 · 675 阅读 · 0 评论 -
c++的友元
1.类中的友元函数,可以无视private protected等修饰符,直接访问类中的所有成员。而且友元函数不受private protected等修饰符的限制,只要写了就是public。 #include <iostream> using namespace std; class A{ private:const int h=55; protected:const int m=10; void print() { cout << "ssss" << endl原创 2021-11-25 20:22:58 · 445 阅读 · 0 评论 -
c++的拷贝构造函数
include <iostream> using namespace std; class Student { private: int num; char *name; public: Student(); ~Student(); }; Student::Student() { name = new char(20); cout << "Student" << endl; } Student::~Stud.原创 2021-10-13 20:27:41 · 51 阅读 · 0 评论