C++拾遗(三)
摘要:declaration and definitionAny variable can be defined for only once. On the contrary, declaration is different. Extern declaration is not definition and does not allocate memory for the variable. 2. cin and getlinegetline ignore space, so in case I wanna input something like space inside my string,
阅读全文
posted @
2011-12-14 14:04
bovine
阅读(301)
推荐(0)
c++拾遗(二)
摘要:虚函数使得在基类声明的函数能够在各个派生类里面重新定义。比如下面这个例子 1: #include <iostream> 2: #include <string> 3: using namespace std; 4: class Employee{ 5: string first_name, family_name; 6: short department; 7: public: 8: Employee(const string &n, int d); 9: virtual void print() const; 10: };...
阅读全文
posted @
2011-12-10 22:29
bovine
阅读(184)
推荐(0)
c++ 拾遗
摘要:typedef的用法typedef的作用是真正意义上地定义一种别名,而不是一种简单的宏替换。typedef 与 #define的区别:案例一:通常讲,typedef要比#define要好,特别是在有指针的场合。请看例子:typedef char *pStr1;#define pStr2 char *;pStr1 s1, s2;pStr2 s3, s4;在上述的变量定义中,s1、s2、s3都被定义为char *,而s4则定义成了char,不是我们所预期的指针变量,根本原因就在于#define只是简单的字符串替换而typedef则是为一个类型起新名字。注意语句char* pa,pb; 其中pa定义
阅读全文
posted @
2011-12-09 16:25
bovine
阅读(280)
推荐(0)