Elementary¶
Basic Ideas¶
- object-oriented | 物件导向-面向对象
An object, or entity(either visible or invisible), is a variable in programming languages, made up of two primary components:
- Attibutes, or Data, representing the object's properties and status
- Services, or Operations, refered to as functions in programming.
C++ Focuses on things instead of operations.
Key words¶
- interface
- communications
- protection
- the hidden implementation
- encapsulation
OOP characteristics¶
- Everything is an object.
- A program is a bunch of objects telling each other what to do/(not how to do) by sending messages
- Each object has its own memory made up of other objects.
- Every object has a type.
- All objects of a particular type can receive the same messages. (Using the method to distinguish between different types or classes)
Header Files¶
To prevent defining repeatedly:
or the same as C language:declaration¶
- external variables
- function prototypes
- class/struct declarations
:: resolver¶
::
<Class Name>::<function name>//not free
::<function name>
void S::f(){
::f();//would be recursive otherwise
::a++;//select the global a
a—;//select the partial a
}
String¶
- A class type, not a primitive type.
- Initially
name
is all zero. No matter it is static or global. - No
\0
at the end of the string.
Reference¶
Reference make use of the idea of a pointer, but is used as a normal variable rather than pointer. It is widely used in passing variables into a function.
Some notes on reference:
- cannot be
NULL
. - cannot calculate.
- No reference to reference