摘要:
string 类型在头文件 string 内,定义在 std 命名空间中。 定义和初始化 string s1; string s2(s1); //拷贝初始化 string s2=s1; //同上 string s3("hello world "); //使用字面值初始化 string s4(10,' 阅读全文
posted @ 2019-02-26 21:14
我是好人007
阅读(315)
评论(0)
推荐(0)
摘要:
头文件保护符用 #ifdef 和 #ifndef ,检查结果为真时, 执行后续操作直至遇到#endif指令。 // 代码取自 C++ primer 第五版 #ifndef SALES_DATA_H #define SALES_DATA_H #include<string> struct Sales_ 阅读全文
posted @ 2019-02-26 19:49
我是好人007
阅读(336)
评论(0)
推荐(0)
摘要:
auto 类型说明符可以让编译器来为我们分析表达式所属的类型: int a=0; auto b=a; //b 为 int 类型 auto 会忽略掉顶层 const (当为指针时为常量指针),会保留底层 const (指向常量的指针),即 auto 不会出现常量指针类型。 阅读全文
posted @ 2019-02-26 19:43
我是好人007
阅读(594)
评论(0)
推荐(0)
摘要:
一般来说,顶层 const 可以表示任意对象是常量,底层 const 则与指针和引用的符合类型有关(指向的是常量): const int a = 2; //顶层 const const int *p = &a; //底层const const int &r = a; //用于声明引用的 const 阅读全文
posted @ 2019-02-26 19:42
我是好人007
阅读(321)
评论(0)
推荐(0)
摘要:
decltype 说明符作用是选择并返回操作数的数据类型: const int ci=0,&pi=ci; decltype(ci) x = 0; //x的类型为 const int decltype(pi) y = 0; // y 的类型为 const int&,绑定到x decltype( f( 阅读全文
posted @ 2019-02-26 19:28
我是好人007
阅读(242)
评论(0)
推荐(0)
摘要:
在C++11的新标准中,using 也用于别名声明,与 typedef 功能相同。 using double wages; //与 typedef double wages 功能相同。 阅读全文
posted @ 2019-02-26 19:13
我是好人007
阅读(490)
评论(0)
推荐(0)
摘要:
constexpr 类型变量必须用常量表达式或 constexpr 函数来初始化: constexpr int a=10; constexpr int b=a+10; constexpr int c=d(); //当 d()为一个 constexpr 函数时才可以 constexpr 函数的形参和返 阅读全文
posted @ 2019-02-26 19:05
我是好人007
阅读(1325)
评论(0)
推荐(0)
摘要:
常量指针为顶层 const,即把 * 放在 const 关键字之前。 例如: int a=0; int *const pa=&a; // pa 为常量指针 一直指向a 指针指向的是一个常量为底层 const,* 放在 const 之后。 例如: const int b=0; const int *p 阅读全文
posted @ 2019-02-26 18:52
我是好人007
阅读(171)
评论(0)
推荐(0)

浙公网安备 33010602011771号