- 博客(10)
- 收藏
- 关注
原创 c++static关键字
#include using namespace std;class A{ static int i;public: static int j; static void set_i(int a){ //用静态方法访问静态属性 i = a; } void print() {
2017-07-28 15:21:46
211
原创 c++const关键字
#include using namespace std;class A{public: const int i; int j; A(int m):i(m){ //必须通过参数列表对const修饰的对象进行初始化 } ~A(){ } void set_j(int n){
2017-07-28 15:20:57
339
原创 c++浅复制
#include #include using namespace std;class A{public: char *p; A(char *src){ p = new char[128]; //在堆区开辟了新空间,然后复制构造器没有重写,复制的对象与被复制的对象同时指向堆区同一片空间,为浅复制 st
2017-07-28 15:19:27
180
原创 c++深复制
#include #include using namespace std;class A{public: char *p; A(char *src){ p = new char[128]; strcpy(p,src); } A(A &a){ //重写复制构造器,为通过
2017-07-28 15:18:57
242
原创 +,++运算符重载
#include using namespace std;class A{ int i; int j;public: A(int m = 0,int n= 0):i(m),j(n){ } ~A(){ } A operator++() { ++(this->i
2017-07-28 15:17:30
201
原创 逻辑与和逻辑或运算符重载
#include using namespace std;class A{public: int i; A(int m = 0):i(m){ } A operator++(){ cout ++(this->i); return *this; } A
2017-07-28 15:16:04
392
原创 输入输出运算符重载
#include using namespace std;class A{public: int i; int j; A(int m, int n):i(m),j(n){ } ~A(){ }};ostream& operator{ os return os;
2017-07-28 15:15:05
223
原创 new,delete运算符重载
#include #include using namespace std;class A{ int i; int j;public: A(){ cout } void *operator new(size_t size) { void *p; p =
2017-07-28 15:12:52
384
原创 c++多态,子类和父类方法的调用
#include using namespace std;class A{public: void run(){ cout } virtual void run0(){ cout } A(){ cout } virtual ~
2017-07-28 15:05:42
4151
原创 c++ string类构造器重写和运算符重载代码
#include #include #include using namespace std;class Mstring{public: char *p; Mstring(); Mstring(char *q); ~Mstring(); Mstring(const Mstring &mstr); Mst
2017-07-27 18:16:47
343
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人