Primary Expression
2016-06-01 17:19
190 查看
Primary expressions are the building blocks of more complex expressions. They are literals, names, and names qualified by the scope-resolution operator (::). A primary expression may have any of the following forms:
A literal is a constant primary expression. Its type depends on the form of its specification. See Literals for complete information about specifying literals.
The this keyword is a pointer to a class object. It is available within nonstatic member functions and points to the instance of the class for which the function was invoked. The this keyword cannot be used outside the body of a class-member function.
The type of the this pointer is type *const (where type is the class name) within functions not specifically modifying the this pointer. The following example shows member function declarations and the types of this:
See Type of this Pointer for more information about modifying the type of the this pointer.
The scope-resolution operator (::) followed by a name constitutes a primary expression. Such names must be names at global scope, not member names. The type of this expression is determined by the declaration of the name. It is an l-value (that is, it can appear on the left hand side of an assignment operator expression) if the declaring name is an l-value. The scope-resolution operator allows a global name to be referred to, even if that name is hidden in the current scope. See Scope for an example of how to use the scope-resolution operator.
An expression enclosed in parentheses is a primary expression whose type and value are identical to those of the unparenthesized expression. It is an l-value if the unparenthesized expression is an l-value.
In the context of the primary expression syntax given above, name means anything in the syntax described for Names, although when using the scope-resolution operator before the name, types of names that can only occur in a class are not allowed. This includes user-defined conversion function names, and destructor names.
Examples of primary expressions include:
The examples below are all considered names, and hence primary expressions, in various forms:
See Also
Types of Expressions
Print Export (0) Share
IN THIS ARTICLE
See Also
Is this page helpful?
literal this :: name name ( expression )
A literal is a constant primary expression. Its type depends on the form of its specification. See Literals for complete information about specifying literals.
The this keyword is a pointer to a class object. It is available within nonstatic member functions and points to the instance of the class for which the function was invoked. The this keyword cannot be used outside the body of a class-member function.
The type of the this pointer is type *const (where type is the class name) within functions not specifically modifying the this pointer. The following example shows member function declarations and the types of this:
// expre_Primary_Expressions.cpp // compile with: /LD class Example { public: void Func(); // * const this void Func() const; // const * const this void Func() volatile; // volatile * const this };
See Type of this Pointer for more information about modifying the type of the this pointer.
The scope-resolution operator (::) followed by a name constitutes a primary expression. Such names must be names at global scope, not member names. The type of this expression is determined by the declaration of the name. It is an l-value (that is, it can appear on the left hand side of an assignment operator expression) if the declaring name is an l-value. The scope-resolution operator allows a global name to be referred to, even if that name is hidden in the current scope. See Scope for an example of how to use the scope-resolution operator.
An expression enclosed in parentheses is a primary expression whose type and value are identical to those of the unparenthesized expression. It is an l-value if the unparenthesized expression is an l-value.
In the context of the primary expression syntax given above, name means anything in the syntax described for Names, although when using the scope-resolution operator before the name, types of names that can only occur in a class are not allowed. This includes user-defined conversion function names, and destructor names.
Examples of primary expressions include:
100 // literal 'c' // literal this // in a member function, a pointer to the class instance ::func // a global function ::operator + // a global operator function ::A::B // a global qualified name ( i + 1 ) // a parenthesized expression
The examples below are all considered names, and hence primary expressions, in various forms:
MyClass // a identifier MyClass::f // a qualified name operator = // an operator function name operator char* // a conversion operator function name ~MyClass // a destructor name A::B // a qualified name A<int> // a template id
See Also
Types of Expressions
Print Export (0) Share
IN THIS ARTICLE
See Also
Is this page helpful?
相关文章推荐
- 数据库----索引的概念及创建
- 设计模式笔记-Memento模式
- SRAM和DRAM的区别
- 自定义异常信息
- el表达式获取div
- ES6学习笔记(七)--Generator函数与Promise对象
- 20 个常用的 CSS 技巧
- poj 2182
- 数组
- quick cocos2dx脚本加密
- hadoop相关随记
- ES6学习笔记(六)--set,map数据结构和for...of遍历
- [从头学数学] 第232节 定积分
- 从0开始学习 GitHub 系列之「Git 速成」
- hadoop相关随记
- docker 监控浅谈
- 团体程序设计天梯赛-练习集 L3-003 社交集群 并查集 解题报告
- CSS3的nth-child() 和nth-of-type()选择器,表格奇偶行变色
- LA 4327 Parade (DP单调队列)
- appledoc 使用方法