C++ Knowledge series 1】的更多相关文章

JVM & Bytecode Has-a or Is-a relationship(inheritance or composition) 如果想利用新类内部一个现有类的特性,而不想使用它的接口,通常应选择合成.也就是说,我们可嵌入一个对象,使自己能用它实现新类的特性.但新类的用户会看到我们已定义的接口,而不是来自嵌入对象的接口.考虑到这种效果,我们需在新类里嵌入现有类的private对象.有些时候,我们想让类用户直接访问新类的合成.也就是说,需要将成员对象的属性变为public.成员对象会将自…
Programming language evolves always along with Compiler's evolvement. 1. The C++ Object Model: Stroustrup's original (and still prevailing) C++ Object Model is derived from the simple object model by optimizing for space and access time. Non-static d…
Function Function is composed of name, parameter (operand, type of operand), return value, body with another adornment like: inline, virtual, static, const, throw(). 我们必须在调用函数之前,就声明该函数否则会引起编译错误. 函数声明由函数返回类型,函数名和参数表构成. 这三个元素被称为函数声明function declaration…
Inheritance The pointer or reference to base class can address/be assigned with any of the classes derived from base class with virtual functions through mechanism of dynamic binding. There are three ways to support polymorphism: through implicit con…
Everything has its lifecycle, from being created to disappearing. Pass by reference instead of pass by value 尽量用“传引用”pass reference 而不用“传值” pass value c语言中,什么都是通过传值来实现的,c++继承了这一传统并将它作为默认方式.除非明确指定,函数的形参parameter总是通过“实参argument的拷贝”来初始化的,函数的调用者得到的也是函数返回…
Thank to the pepole who devote theirself to the common libs. STL(http://www.cplusplus.com/reference/) 旧的C++头文件名如<iostream.h>将会继续被支持,尽管它们不在官方标准official standard中.这些头文件的内容不在名字空间std中.No _STDBEGIN (namespaces std {}and _STDEND. 新的C++头文件如<iostream>…
Pepole who make a greate contribution on common libaraies deserve our respect. Component(Widget) / STL / Container(Collection) 合成不会强迫我们的程序设计进入继承的分级结构中has-a relationship.同时,合成显得更加灵活,因为可以动态选择一种类型(以及行为),而继承要求在编译期间准确地知道一种类型. Java的工具(实用程序)库提供了一些“集合类”(亦称作“…
Programming language evolves always along with Compiler's evolvement The semantics of constructors One of the most often heard complaints about C++ is that the compiler does things behind the programmer’s back. We shall know how underlying compiler d…
Interface from user, not from implementor.(DIP) Interface-Oriented Programming. Interface or Abstract function or Abstract class Java专门提供了一种机制,名为“抽象方法”(same as abstraction).它属于一种不完整的方法,只含有一个声明declaration,没有方法主体 body of definition.下面是抽象方法声明时采用的语法:abst…
JVM & Bytecode Abstract & Object Object in Java (1) 所有东西都是对象object.可将对象想象成一种新型变量:它保存着数据,但可要求它对自身进行操作self-operation(this pointer is always as parameter pssing to function called on object).理论上讲,可从要解决的问题身上提出所有概念性的组件,然后在程序中将其表达为一个对象. (2) 程序是一大堆对象的组合c…