双冒号::被认为是作用域限定操作符,用来指定类中不同的作用域级别.::左边表示的是作用域,右边表示的是访问的成员. 系统定义了两个作用域,self和parent.self表示当前类的作用域,在类之外的代码是不能使用这个操作符的. Program List:使用self作用域访问父类中的函数 <?php class NowaClass { function nowaMethod() { print '我在类 NowaClass 中声明了.'; } } class ExtendNowaClass e…
const限定符限定变量的类型是一个常量,对象一旦创建后其值就无法改变,所以const对象必须初始化. 初始化 const int i = get_size(); //运行时初始化 const int j = 42; //编译时初始化 int k = 40; const int ck = k; //k的值 被拷贝给了ck const对象的作用域 默认情况下,const对象仅在文件内有效. 如果要在多个文件中共享const对象,必须在变量的定义之前添加extern关键字. //file_1.cc定…
有些被称为存储说明符(storage class specifier)或cv-限定符(cv-qualifier)的C++关键字提供了一些有关存储的信息.下面是存储所说明符:* auto (在C++11中不再是说明符);* register;* static;* extern;* thread_local(C++11新增的);* mutable.在同一个声明中不能使用多个说明符,但thread_local除外,它可与static或extern结合使用.在C++11之前,可以在声明中使用关键字aut…
今天看书,Thinking in c++ volume 2 "Adaptable function objects" 里面作者说: Suppose, for example, that we want to make the function object gt_n, definedearlier in this chapter, adaptable. All we need to do is the following: class gt_n : public unary_funct…