
C++
刘秋杉
区块链资深研究者
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++关键字explicit
C++中常会遇到explicit,简而言之,它用于拥有单参数构造函数的类。 class A { public: A(int param); }若出现 A a = 10,则等价于A t(10);A a = t;如果加上explicit,将类的构造函数声明为显式的class A { public: explicit A(int param); }则 A a = 10 编译不通过。没有expli原创 2014-01-23 20:37:18 · 1036 阅读 · 0 评论 -
C++友元
友元成员函数 class Car { friend void Key::set_Sound(Car &c, int s); ... }; 这样在Key::set_Sound()中可以访问Car的私有成员(编译器在处理friend这条语句时,应先看到Key类的声明和set_Sound()方法的声明)。 在声明时要注意循环依赖(若class Key在class Car前声明,Key的成员原创 2014-02-22 13:29:26 · 967 阅读 · 0 评论 -
Command terminated by signal 11
Command terminated by signal 11可能的情况之一是数组越界,你在访问不被允许的内存空间。原创 2014-06-27 21:55:07 · 7778 阅读 · 0 评论 -
#define中的rettype和##
# define DEF(func, kind, rettype, args...) \ rettype tern_ ## func (unsigned insid, ##args); 上面的rettype是宏参数,在实际使用DEF宏时,在rettype位置要有一个参数,然后在宏内容里rettype位置就会被替换为你提供的参数;##用于连接前后两个参数,把它们变成一个字符串。 DEF(原创 2014-06-27 20:40:49 · 4995 阅读 · 0 评论 -
C++类模板template
类模板的出现可以精简代码,设想一下,函数max(int a, int b)求a和b两者中的最大值,如果我要求float型或double型,是否还要写一套max,这样太不优雅了。 先看一下类模板的固定格式——原创 2014-02-23 22:55:46 · 1097 阅读 · 0 评论 -
虚函数对C++多态的影响
class Bird { public: Bird(); virtual ~Bird(); void fly(); virtual void tweet(); virtual void breed()=0; }; class Eagle : public Bird { public: Eagle() : Bird() {} virtual ~Eagle(); void fly()原创 2014-02-10 21:12:16 · 1039 阅读 · 0 评论 -
C++私有继承
当遇到 class A : private B {...}; 就是私有继承,它有一些特性:基类的成员会成为派生类的私有成员,所以有如下示例 #include #include using namespace std; class Engine { public: Engine(int numCylinders) {} void start原创 2014-01-24 15:20:21 · 1134 阅读 · 0 评论 -
C++成员初始化列表
当类的成员用const修饰时,要通过成员初始化列表进行赋值,如: class Dream { private: const int day; public: Dream(int _d) { day = _d; } //error Dream(int _d) : day(_d) {} //correct }; 我们可以分析,const在C++中表示值不能被更新,因此普通的赋值操作无效。原创 2014-02-10 20:45:15 · 1058 阅读 · 0 评论