上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 49 下一页
摘要: // 第二十五章补充内容 12联合数据类型union//联合体与结构体有什么不同之处//1 初始化,联合类型union只能对它的第一个成员进行初始化/*#include <iostream>#include <string>using namespace std;union people{ char name[10]; short int age; float weight;};void show(people);int main(){ people Jack={"Xlc"}; show(Jack); return 0;}void show(peop 阅读全文
posted @ 2012-10-15 21:54 简单--生活 阅读(190) 评论(0) 推荐(0) 编辑
摘要: //第二十五章补充内容 9 关键字volatile//用volatile关键字声明的变量,是用来告诉编译器每次对此变量的引用都需要从内存地址中读取,即取消编译器对此变量的优化编译//volatile可以保证对特殊地址的稳定访问,不会出错//register寄存器变量/*#include <iostream>using namespace std;int dquare(volatile int *p){ return (*p)*(*p);}int func(int n){ register int i, s=0; for(i=0; i<=n; i++) { s = s+i; } 阅读全文
posted @ 2012-10-15 21:48 简单--生活 阅读(136) 评论(0) 推荐(0) 编辑
摘要: // 第二十五章补充内容 10 关键字const//const int a;//int const a//const int *a//int * const a;//int const * a const;//const int a与int const a的作用是一样的,都表示a是一个常整型数//const int *a意味着a是一个指向常整型号数的指针,换句话说,a指向的整型数是不可修改的//int * const a的意思是a是一个指向整型数的常指针,也就是说,指针a指向的整型数是可以修改的,但指针a是不可修的//int const * a const意味着a是一个指向常整型数的常指针,也 阅读全文
posted @ 2012-10-15 21:48 简单--生活 阅读(175) 评论(0) 推荐(0) 编辑
摘要: //第二十五章补充内容 11 关键字mutable//我们知道修饰为const的成员函数,是不能修改类的数据成员的,但是这并不表示它不可以修改经过mutable修饰后的数据成员,关键字mutable将其后的数据修饰为可供const成员函数进行修改的数据成员/*#include <iostream>#include <string>#include <iomanip>using namespace std;class A{public: A(int i):x(i){} int add()const //注意这里是const { return ++x; } vo 阅读全文
posted @ 2012-10-15 21:48 简单--生活 阅读(144) 评论(0) 推荐(0) 编辑
摘要: // 第二十五章补充内容 5 不能为0的变量/*#define DEBUG#include <iostream>#include <string>using namespace std;#ifndef DEBUG#define ASSCET(x)#else#define ASSCET(x)\ if(!(x))\ {\ cout<<"错误!ASSERT("<<#x<<")宏函数执行失败"<<endl;\ cout<<"错误的代码出现在第"<< 阅读全文
posted @ 2012-10-15 21:47 简单--生活 阅读(194) 评论(0) 推荐(0) 编辑
摘要: // 第二十五章补充内容 6 用宏函数来输出表达式的值/*#define DEBUG#include <iostream>using namespace std;#ifndef DEBUG#define show(x)#else#define show(x)\ cout<<#x<<": \t"<<x<<endl;#endifint main(){ int x = 9; show(x); //9 int *y = &x; show(*y); //9 show(y); //内存地址 char *ch=" 阅读全文
posted @ 2012-10-15 21:47 简单--生活 阅读(156) 评论(0) 推荐(0) 编辑
摘要: // 第二十五章补充内容 7 调试的级别/*#include <iostream>#include <string>using namespace std;#define DEBUG 2#if DEBUG < 2 #define ASSERT(x)#else#define ASSERT(x)\if(!(x))\{\ cout<<"错误!Assert("<<#x<<")宏函数执行失败"<<endl;\ cout<<"错误代码出现在第"<< 阅读全文
posted @ 2012-10-15 21:47 简单--生活 阅读(209) 评论(0) 推荐(0) 编辑
摘要: //第二十五章补充内容 8 C++类型转换及运行时类型信息(RTII)//C++中有四种新风格的类型转换操作符,每一种操作符返回的是一个根据类型转换操作符规则转换后的对像//cast_operator<type>(object)//type代表要转换的类型//object代表要转换的对像//而cast_operator则是执行转换的操作符,它通常有四种形式,分别为动态类型转换,静态类型转换,重新解释类型转换和常类型转换符//8.1 动态类型转换符//动态类型转换符将一个基类的引用或者指针转换为一个派生类的引用或者指针,我们把它叫做向下类型转换//或者将一个派生类的引用或指针转换为基 阅读全文
posted @ 2012-10-15 21:47 简单--生活 阅读(1258) 评论(0) 推荐(0) 编辑
摘要: //第二十五章补充内容 3 assert()宏//有的编译器还提供了assert()宏,这个宏在许多书中被翻译为断言,它的作用是当assert()的参数为真时,返回真,假如参数值为假,那么它将执行某种操作/*#include <iostream>#include <assert.h>using namespace std;void main(){ float a, b; cout<<"请输入除数:"<<endl; cin>>a; cout<<"请输入被除数:"<<endl 阅读全文
posted @ 2012-10-15 21:46 简单--生活 阅读(163) 评论(0) 推荐(0) 编辑
摘要: //第二十五章补充内容 4 尝试编写一个简单的assert()宏/*#include <iostream>using namespace std;//结尾处的正斜杠"\"将本行语句与后面的语句连为一句#define ASSERT(x)\ if(!(x))\ {\ cout<<"错误!ASSERT("<<#x<<")宏函数执行失败"<<endl; \ cout<<"错误代码出现在第"<<__LINE__<<"行& 阅读全文
posted @ 2012-10-15 21:46 简单--生活 阅读(137) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 49 下一页
简单--生活(CSDN)