Primary Expression
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:
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
Is this page helpful?
Primary Expression的更多相关文章
- javascript 核心语言笔记 4 - 表达式和运算符
表达式(expression)是 JavaScript 中的一个短语(phrases),JavaScript 解释器会将其计算(evaluate)出一个结果.程序中的常量.变量名.数组访问等都是表达式 ...
- angular源码分析:angular中脏活累活承担者之$parse
我们在上一期中讲 $rootscope时,看到$rootscope是依赖$prase,其实不止是$rootscope,翻看angular的源码随便翻翻就可以发现很多地方是依赖于$parse的.而$pa ...
- go语言的selector
For a primary expression x that is not a package name, the selector expression x.f denotes the field ...
- 【C】 04 - 表达式和语句
程序的生命力体现在它千变万化的行为,而再复杂的系统都是由最基本的语句组成的.C语句形式简单自由,但功能强大.从规范的角度学习C语法,一切显得简单而透彻,无需困扰于各种奇怪的语法. 1. 表达式(exp ...
- javascript5
调用对象call object: 声明上下文对象declarative environment record; 作用域链scopechain: 变量解析:variable resolution: 引用 ...
- Method Invocation Expressions
15.12.1. Compile-Time Step 1: Determine Class or Interface to Search The first step in processin ...
- C++程序设计语言(特别版) -- 一个桌面计算器
前言 这里要介绍各种语句和表达式,将通过一个桌面计算器的程序做些事情,该计算器提供四种座位浮点数的中缀运算符的标准算术运算. 这个计算器由四个部分组成:一个分析器,一个输入函数,一个符号表和一个驱动程 ...
- 笔记《JavaScript 权威指南》(第6版) 分条知识点概要3—表达式和运算符
[表达式和运算符]原始表达式,初始化表达式(对象和数组的),函数定义表达式,属性访问表达式,调用表达式,对象创建表达式,运算符概述,算术表达式,关系表达式,逻辑表达式,赋值表达式,表达式计算,其他运算 ...
- Swift5 语言参考(十) 语法汇总
词法结构 GRAMMAR OF WHITESPACE whitespace → whitespace-item whitespace opt whitespace-item → line-break ...
随机推荐
- 数学概念——G 最大公约数
G - 数论,最大公约数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 《傲慢与偏见》(Pride and Prejudice)
<傲慢与偏见>(Pride and Prejudice)改编自英国作家简·奥斯汀的同名小说,1940年上映.讲述了19世纪初期英国的一个普通的中产家庭中五姐妹的爱情与择偶故事.片中因为男主 ...
- HDU 1203 I NEED A OFFER! 01背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 解题思路:简单的01背包,用dp[i]表示花费不超过i时的最大可能性 状态转移方程 dp[i]= ...
- PL/SQL Developer 与tnsnames.ora
PL/SQL Developer 是一款流行的oracle开发与管理的IDE. 在登录PL/SQL Developer时所选择的数据库依赖于tnsnames.ora文件中的信息. 如果我们安装了多个o ...
- Hard 计算0到n之间2的个数 @CareerCup
一种是Brute force,O(nlogn) 另一种是找规律O(n),见http://hawstein.com/posts/20.4.html 当某一位的数字小于2时,那么该位出现2的次数为:更高位 ...
- TCP/UDP 、HTTP、IP 、socket 的关系。
网络有上下分为7 层.物理层,数据链路层.网络层.会话层.应用层.传输层: IP协议位于网络层,IP和端口来控制网络流向: TCP.UDP是基于传输层.TCP保证三次握手.传递数据: UDP为不考虑是 ...
- SQLServer2005 常用语法大全
SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRAN ...
- evernote出现"Invalid username and/or password"的情况
evernote出现"Invalid username and/or password"的情况 evernote挺好用的,可是这几年用下来也遇到过狗血情况,几乎每次都是更新后出状况 ...
- [Angular 2] Template property syntax
This lesson covers using the [input] syntax to change an element property such as “hidden” or “conte ...
- Qt国际化详细介绍,中文乱码以及解决方案
Qt国际化的一般步骤 运行 lupdate,从应用程序的代码中提取所有界面上的可见字符. 这些可见字符必须被 tr() .QCoreApplication::translate().Qt ...