TCPL_4 types and declarations

来源:互联网 发布:淘宝搜索屏蔽关键词 编辑:程序博客网 时间:2024/04/30 10:10

4.1 types

consider x=y+f(2); For this to make sense in a c++ program, the names x, y, and f must be suitably declared. That is, the programmer must specify that entities named x, y, and f exit and that they are of types for which =(assignment), +(addition), and()(function call), respectively, are meaningful.

c++程序中出现的名字在使用之前必须被合理的声明,就是说,程序员必须指定实体x, y, f,是存在的,并且这三个实体的类型具有这样的特点,当赋值操作,加操作,函数调用操作作用在这些类型的对象上时,这些操作是有意义的。

Every name(identifier) in a c++ program has a type associated with it. This type determines what operations can be applied to the name(that is, to the entity referred to by the name) and how such operations are interpreted.

float x;       // x is a floating-point variable

int y;          // y is an integer variable with the initial value 7

float f(int); // f is a function taking an argument of type int and returning a floating-point number

would make the example meaningful.(将能使x=y+f(2);有意义),顺便说一下,我觉得赋值操作符,加操作符,实际上都是函数,针对于自定义类型时,我们重载操作符,不也是把这些操作符来当作函数来处理的么,扩展一上,最好不要把操作符与变量之间加上空格,那样好像是把函数与参数分开了定一样不好。

4.1.1 fundamental types

c++ has a set of fundamental types corresponding to the most

原创粉丝点击