C/C++
chenfj01
这个作者很懒,什么都没留下…
展开
-
assert
As long as NDEBUG is not defined, the assert macro evaluates the condtion and if the result is false, then assert writes a message and terminates the program. If the expression has a nonzero (e.g., tr原创 2005-12-17 21:00:00 · 804 阅读 · 0 评论 -
默认参数
1、默认参数一般在函数声明中提供,如果程序中既有函数声明又有函数定义,函数定义中不允许再定义参数的默认值,即使指定的默认值完全相同也不行。下面是错误的,默认参数不能同时出现在函数声明与函数定义中: // ff.h int ff(int = 0); // ff.cc #include "ff.h" int ff(int i = 0) { /* ... */ }原创 2006-01-04 09:57:00 · 1196 阅读 · 0 评论 -
const参数
What may be surprising, is that although the parameter is a const inside the function, the compiler otherwise treats the definition of fcn as if we had defined the parameter as a plain int: void f原创 2006-01-03 11:35:00 · 866 阅读 · 0 评论 -
关于数组
下面两个声明是等同的,注意二维数组的声明方法,尤其是第一种方法。 // first parameter is an array whose elements are arrays of 10 ints void printValues(int (matrix*)[10], int rowSize); // first parameter is an array whose elements原创 2006-01-03 15:34:00 · 767 阅读 · 0 评论 -
string/vector/iterator
// an iterator that cannot write elements vector::const_iterator // an iterator whose value cannot change const vector::iteratorTable 3.2. string Operationss.empty()Returns true if s原创 2006-01-04 09:33:00 · 1550 阅读 · 0 评论 -
const member function不明白
class中,成员函数 const string& GetName()const{ return name}第一个const与第二个const。。。不明白。我的理解:第一个const,返回值为常量值。第二个const,表明在该成员函数中不可以改变成员变量的值。(是不是就是认为成员变量为常量?象上面的函数返回值是不是就只能为const string,而不能为string?)原创 2006-01-14 20:07:00 · 1274 阅读 · 3 评论 -
构造函数(有关初始列表)
For example, the following constructor is in error: class ConstRef { public: ConstRef(int ii); private: int i; const int ci; //常量 int &ri;原创 2006-01-14 22:01:00 · 1121 阅读 · 1 评论 -
名字在编译时识别
class Disc_item : public Item_base { public: std::pair discount_policy() const { return std::make_pair(quantity, discount); } // other members as before };We can原创 2006-03-12 13:23:00 · 951 阅读 · 0 评论 -
堆与栈的区别
(转载) 堆和栈的区别 堆: 是大家共有的空间,分全局堆和局部堆。全局堆就是所有没有分配的空 间,局部堆就是用户分配的空间。堆在操作系统对进程 初始化的时候分配,运 行过程中也可以向系统要额外的堆,但是记得用完了要还给操作系统,要不然就 是内存泄漏。堆里面一般 放的是静态数据,比如 Static的数据和字符 串常量等,资源加载后一般也放在堆里面。一个进程的所有线程共有这些堆 , 所以对堆的操作转载 2006-02-26 21:05:00 · 911 阅读 · 0 评论