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
 
 
IN THIS ARTICLE
  • See Also

Is this page helpful?

Primary Expression的更多相关文章

  1. javascript 核心语言笔记 4 - 表达式和运算符

    表达式(expression)是 JavaScript 中的一个短语(phrases),JavaScript 解释器会将其计算(evaluate)出一个结果.程序中的常量.变量名.数组访问等都是表达式 ...

  2. angular源码分析:angular中脏活累活承担者之$parse

    我们在上一期中讲 $rootscope时,看到$rootscope是依赖$prase,其实不止是$rootscope,翻看angular的源码随便翻翻就可以发现很多地方是依赖于$parse的.而$pa ...

  3. go语言的selector

    For a primary expression x that is not a package name, the selector expression x.f denotes the field ...

  4. 【C】 04 - 表达式和语句

    程序的生命力体现在它千变万化的行为,而再复杂的系统都是由最基本的语句组成的.C语句形式简单自由,但功能强大.从规范的角度学习C语法,一切显得简单而透彻,无需困扰于各种奇怪的语法. 1. 表达式(exp ...

  5. javascript5

    调用对象call object: 声明上下文对象declarative environment record; 作用域链scopechain: 变量解析:variable resolution: 引用 ...

  6. Method Invocation Expressions

      15.12.1. Compile-Time Step 1: Determine Class or Interface to Search   The first step in processin ...

  7. C++程序设计语言(特别版) -- 一个桌面计算器

    前言 这里要介绍各种语句和表达式,将通过一个桌面计算器的程序做些事情,该计算器提供四种座位浮点数的中缀运算符的标准算术运算. 这个计算器由四个部分组成:一个分析器,一个输入函数,一个符号表和一个驱动程 ...

  8. 笔记《JavaScript 权威指南》(第6版) 分条知识点概要3—表达式和运算符

    [表达式和运算符]原始表达式,初始化表达式(对象和数组的),函数定义表达式,属性访问表达式,调用表达式,对象创建表达式,运算符概述,算术表达式,关系表达式,逻辑表达式,赋值表达式,表达式计算,其他运算 ...

  9. Swift5 语言参考(十) 语法汇总

    词法结构 GRAMMAR OF WHITESPACE whitespace → whitespace-item whitespace opt whitespace-item → line-break ...

随机推荐

  1. HDOJ(HDU) 2123 An easy problem(简单题...)

    Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...

  2. VMware宿主机和虚拟机的网络连接问题

    今天在win8上装了个vmware虚拟机,却发现一个vmware workstation宿主机ping不通centos虚拟机,宿主机和centos虚拟机都可以正常上网. 问题描述:今天在vmware ...

  3. bzoj 1089 [SCOI2003]严格n元树(DP+高精度)

    1089: [SCOI2003]严格n元树 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1250  Solved: 621[Submit][Statu ...

  4. 【最短路】埃雷萨拉斯寻宝(eldrethalas) 解题报告

    问题来源 BYVoid魔兽世界模拟赛 [问题描述] 一万两千年前,当精灵还是在艾萨拉女王的统治下的时候,辛德拉就是是女王手下一名很有地位的法师了.他受任建造了一座城市,来保存女王的法师们进行魔法研究的 ...

  5. Eucalyptus安装包的功能列表

    aoetools    是一个用来在以太网上运行 ATA 存储协议的软件,相当于一个网络存储功能.euca2ools  eucalpytus客户端杜昂管理工具axis2c       SOAP引擎,同 ...

  6. 使用Linux的命令行工具做简单的文本分析

    Basic Text Analysis with Command Line Tools in Linux | William J Turkel 这篇文章非常清楚的介绍了如何使用Linux的命令行工具进 ...

  7. 【protobuf进阶】读取proto实体里的extensionObject对象的方法

    //设置扩展对象 ProtoBuf.Extensible.AppendValue //读取扩展对象 ProtoBuf.Extensible.GetValue 最近通过C#的TcpClient调用jav ...

  8. 再回首,Java温故知新(六):Java基础之变量

    变量在所有的编程语言中都有,属于最最基础的部分,学习这部分基本不分语言,变量可分为成员变量和局部变量 Java中变量的声明格式如下,修饰符如果不加,默认是default,关于修饰符,我们会在后续讲到, ...

  9. Java的容器小结

    1. 各个类与接口的关系:

  10. servlet 配置到服务器

    最近写了个安卓项目,服务端用的servlet.因为第一次写java项目,写完如何发布不是太清除,于是把这回经理写出来,一来做个记录,二来也给和我同样经历的朋友一点启示. 首先配置你的java主机和你的 ...