chap10 name control
来源:互联网 发布:莎莎源码 编辑:程序博客网 时间:2024/05/10 13:01
namespace特点:
namespace myLib
{
....
}//(1)没有“;”
(2)可以在多个头文件里定义,不算redefinition
(3)A namespace definition can appear only at global scope, or nested within
another namespace.
(4)赋值,如果原来的namespace的名字太长,可以用简单的名字代替
e.g namespace shortName = tooLongName;
static member data & static member function
//: C10:StaticMemberFunctions.cpp
class X {
int i;
static int j;
public:
X(int ii = 0) : i(ii) {
// Non-static member function can access
// static member function or data:
j = i;
}
int val() const { return i; }
static int incr() {
//! i++; // Error: static member function
// cannot access non-static member data
return ++j;
}
static int f() {
//! val(); // Error: static member function
// cannot access non-static member function
return incr(); // OK -- calls static
}
};
int X::j = 0;//初始化静态成员变量
int main() {
X x;
X* xp = &x;
x.f();//also works
xp->f();//also works
X::f(); // Only works with static members
} ///:~
NOTE: 当对象调用一般的成员函数时,都会传入一个this指针,而对于静态成员函数,
是属于整个类的,不会传入this指针,所以不能调用一般的成员变量和一般的成员函数。
alternate linkage specificationse.g
extern "C" {
float f(int a, char b);
double d(int a, char b);
#include "xxxx.h"
}
namespace myLib
{
....
}//(1)没有“;”
(2)可以在多个头文件里定义,不算redefinition
(3)A namespace definition can appear only at global scope, or nested within
another namespace.
(4)赋值,如果原来的namespace的名字太长,可以用简单的名字代替
e.g namespace shortName = tooLongName;
static member data & static member function
//: C10:StaticMemberFunctions.cpp
class X {
int i;
static int j;
public:
X(int ii = 0) : i(ii) {
// Non-static member function can access
// static member function or data:
j = i;
}
int val() const { return i; }
static int incr() {
//! i++; // Error: static member function
// cannot access non-static member data
return ++j;
}
static int f() {
//! val(); // Error: static member function
// cannot access non-static member function
return incr(); // OK -- calls static
}
};
int X::j = 0;//初始化静态成员变量
int main() {
X x;
X* xp = &x;
x.f();//also works
xp->f();//also works
X::f(); // Only works with static members
} ///:~
NOTE: 当对象调用一般的成员函数时,都会传入一个this指针,而对于静态成员函数,
是属于整个类的,不会传入this指针,所以不能调用一般的成员变量和一般的成员函数。
alternate linkage specificationse.g
extern "C" {
float f(int a, char b);
double d(int a, char b);
#include "xxxx.h"
}
- chap10 name control
- chap10-queue
- chap10-DLinkList
- thinking in c++ 读书笔记---name control
- change db name by recreating control file
- Name lookup take place before access control
- thinking in c++之Name control
- chap10 list 单链表实现
- chap10 单链表倒置
- Note of Chap10
- 英语学习--chap10 介词
- CSAPP Note chap10
- DE2-70 Control Panel "Fail to query board name"
- 【Angular4】No value accessor for form control with name: '***'
- 基础文章1:APUE chap10 信号
- Control
- Control
- Control
- 常量函数、常量引用参数、常量引用返回值[C++]
- 我的网站。。大家顶一下啦
- chap1--chpa7
- chap8 const
- chap9 inline function
- chap10 name control
- chap11 reference
- chap12 operator overload
- chap13 Dynamic Object Creation
- 有一种爱叫做放手
- 名言
- ibatis学习记录(2)
- 老紫竹JAVA基础培训(2)熟悉方法的调用
- 界面库 / 皮肤库 KWndLib V1.0.1.6