随笔分类 -  c/c++

static在类中的定义,和enum的用法
摘要:class A { // static int a = 1;//错误,静态变量在类外定义 static int a; static const int b = 1;//如果是静态成员常量,则可以在类内定义 static const int c;//也可以在外面定义 }; int A::a = 1;//类外定义静态成员变量; const int A::c = 1;//在外面定义的静态成员常量... 阅读全文

posted @ 2016-06-13 17:26 Kooing 阅读(631) 评论(0) 推荐(0)

新版本的strcpy_s
摘要:以后指针的东西就不要用strcpy函数了,麻烦 阅读全文

posted @ 2016-06-13 17:02 Kooing 阅读(186) 评论(0) 推荐(0)

函数传参的对象问题
摘要:doSometing(A(29));// 是可以得(至少在vs)doSometing(new A(20))//如果不可以的话在堆空间中申请了 doSometing(const A& a); doSometing(A a);//和上面的一个道理,两者选其一 阅读全文

posted @ 2016-06-12 00:04 Kooing 阅读(176) 评论(0) 推荐(0)

在同个类中non-const插入const来减少重复
摘要:class A { private: std::string a; public: A(std::string b) :a(b){} const char& operator[](int b)const { std::cout //分两部分,一部分是消掉const (static_... 阅读全文

posted @ 2016-06-11 10:56 Kooing 阅读(241) 评论(0) 推荐(0)

成员函数的const不能被修改,包括指针
摘要:#include class A { private: std::string a; public: A(std::string b) :a(b){} const char& operator[](int b)const //两个const都不能少 { return a[b]; } }; int main() { A a("he... 阅读全文

posted @ 2016-06-11 10:20 Kooing 阅读(335) 评论(0) 推荐(0)

括号计算器
摘要://这计算器支持括号功能,格式例子3+(3*3)## ,后面打两个#算结束,还有阶乘和次方等功能留给同学们自己完善#include using namespace std; template struct Node {//这个是数据结构模板,char和int都可以用 T data; Node* next; }; template class stack { Node... 阅读全文

posted @ 2016-05-10 21:29 Kooing 阅读(628) 评论(0) 推荐(0)

导航