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 ...
随机推荐
- PHP学习之[第11讲]新浪微博开放平台 PHP 与 OAuth 接口(1)
我是下载的微博最新的API练习了一下认证过程.
- 双系统如何正确的使用修复BCD工具分享
安装双系统时候,用于种种原因会导致开机启动只显示一个系统,此时需要修复下BCD即可. 下面介绍下两个修复BCD工具软件: 1.easybcd(双系统引导修复工具) v2.2.0.182 汉化版 下载地 ...
- Linux命令 - 删除文件(夹)
1.删除文件夹 rm –rf /var/test 将会删除/var/test目录以及其下的所有文件.文件夹 2.删除文件 rm -f /var/test/test.txt 将会强制删除/var/tes ...
- Android ViewPager PagerAdapter 图片轮播
ViewPager类直接继承了ViewGroup类,所有它是一个容器类,可以在其中添加其他的View类. ViewPager类需要一个PagerAdapter适配器类给它提供数据. ViewPager ...
- [Javascript] Logging Pretty-Printing Tabular Data to the Console
Learn how to use console.table to render arrays and objects in a tabular format for easy scanning ov ...
- (黑客游戏)HackTheGame1.21 过关攻略
第一关: 标题 : 您好 来自 : chaozz@fake-mail-address.com ----------------------------------------------------- ...
- 在 foreach 里使用引用要注意的陷阱(转)
从一道面试题开始 在开始本节内容前,我们先来看看一道还算比较常见的PHP面试题: 1 $arr = array('1','2','3'); 2 3 foreach($arr as &$v) ...
- JBoss EAP6/AS7/WildFly: How to Use Properties Files Outside Your Archive--reference
Introduction I’d like to preface this post with, really, all properties files should be inside your ...
- 笔试之STL
1. map是如何实现的?它的keys是否经过排序?如何实现它的clear方法? A 实现: map是通过红黑树来实现的,keys是经过排序的: map的所有元素都是pair,同时拥有实值(value ...
- Java基础知识强化之IO流笔记21:FileInputStream读取数据
1. 字节输入流的操作步骤: (1)创建字节输入流的对象 (2)调用read()方法读取数据,并把数据显示到控制台 (3)关闭字节输入流的对象资源 2. FileInputStream构造: File ...