C++
pp-hu
这个作者很懒,什么都没留下…
展开
-
指向函数的指针
在函数中,形参不能为函数类型,但可以是指向函数的指针,此时,形参看起来是函数类 型,实际上当作指针使用。 //ptr为指向函数的指针 //第三个形参是函数类型,会自动转换成函数的指针 void f(const string &s1,const string &s2,bool ptr(int a,int b) ); //第三个形参是函数指针 void f(const string...原创 2018-08-23 21:35:35 · 137 阅读 · 0 评论 -
常量成员函数,指向this的指针
在类中,形如 Test combine(const Test &latter) const { num += latter.num; return *this; } 这样的成员函数为常量成员函数。当Test的对象调用combine函数时,隐式指针this会指向调用该函数的对象,this指针默认为常量指针,即Test *const类...原创 2018-08-25 18:06:10 · 495 阅读 · 0 评论 -
隐式的类类型转换
正如C++内置类型在赋值时可以进行隐式的类型转换,我们也能为类定义隐式转换规则: class Sale_data { public: Sale_data(const int &x):it(x) {} Sale_data &combine(const Sale_data &temp) { it += temp.it; ...原创 2018-09-06 21:39:16 · 119 阅读 · 0 评论 -
链式存储——链表的创建和遍历
#include<iostream> using namespace std; //链表结构体 struct LNode { int data; LNode* next; }; //创建一个含有n个结点的链表,L1为头结点 //结点data元素从1开始递增,步长为1 void create(LNode &L1,int n) { int i = 2; ...原创 2018-09-26 22:08:13 · 458 阅读 · 0 评论