`
talin2010
  • 浏览: 501821 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

17.9.1 Unary operators

阅读更多
The following rules apply to unary operator declarations, where T denotes
the class or struct type that contains
the operator declaration:
? A unary +, -, !, or ~ operator must take a single parameter of type T and
can return any type.
? A unary ++ or -- operator must take a single parameter of type T and must
return type T.
? A unary true or false operator must take a single parameter of type T and
must return type bool.
The signature of a unary operator consists of the operator token (+, -, !,
~, ++, --, true, or false) and the type
of the single formal parameter. The return type is not part of a unary
operator?s signature, nor is the name of the
formal parameter.
C# LANGUAGE SPECIFICATION
256
The true and false unary operators require pair-wise declaration. A
compile-time error occurs if a class
declares one of these operators without also declaring the other. The true
and false operators are described
further in §14.16.
[Example: The following example shows an implementation and subsequent
usage of operator++ for an integer
vector class:
public class IntVector
{
public int Length { ? } // read-only property
public int this[int index] { ? } // read-write indexer
public IntVector(int vectorLength) { ? }
public static IntVector operator++(IntVector iv) {
IntVector temp = new IntVector(iv.Length);
for (int i = 0; i < iv.Length; ++i)
temp[i] = iv[i] + 1;
return temp;
}
}
class Test
{
static void Main() {
IntVector iv1 = new IntVector(4); // vector of 4x0
IntVector iv2;
iv2 = iv1++; // iv2 contains 4x0, iv1 contains 4x1
iv2 = ++iv1; // iv2 contains 4x2, iv1 contains 4x2
}
}
Note how the operator method returns the value produced by adding 1 to the
operand, just like the postfix
increment and decrement operators(§14.5.9), and the prefix increment and
decrement operators (§14.6.5). Unlike
in C++, this method need not, and, in fact, must not, modify the value of
its operand directly. end example]
分享到:
评论

相关推荐

    The C Programming Language 第二版 英文版

    Chapter 1 - A Tutorial Introduction.............................. 1.1 Getting Started................................ 1.2 Variables and Arithmetic Expressions........... 1.3 The for statement.........

    Prentice.Hall.C++.for.Business.Programming.2nd.Edition.2005.chm

    Preface xv Changes From the First Edition xvi Chapter Overview xvii ... Section B.1. Sequence 802 Section B.2. Selection 803 Section B.3. Iteration 808 Section B.4. Combinations 812 Index

    Google C++ International Standard.pdf

    1 Scope 1 2 Normative references 2 3 Terms and definitions 3 4 General principles 7 4.1 Implementation compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4.2 Structure ...

    Guide to Scientific Computing in C++

    2.2 Logical and Relational Operators . . . . . . . . . . . . . . . . 2.3 The while Statement . . . . . . . . . . . . . . . . . . . . . . 2.4 Loops Using the for Statement . . . . . . . . . . . . . . ....

    Turbo Assembler 2.0 Quick Reference

    Part 1 Predefined symbols $ .......................... 2 @code ...................... 2 @CodeSize .................. 2 @CPU ...................... 2 @curseg .................... 2 @data .................

    Addison.Wesley.C++.by.Dissection.2002.pdf

    3.24.1 Vector Instead of Array..... . . . 123 3.24.2 String Instead of char*..... . . . 124 3.25 Software Engineering: Program Correctness.... 124 3.26 Dr. P’s Prescriptions....... . . 127 3.27 C++ ...

    Thinking in Java 4th Edition

    Preface 1 Java SE5 and SE6 .................. 2 Java SE6 ......................................... 2 The 4th edition........................ 2 Changes .......................................... 3 Note...

    C++ 标准 ISO 14882-2011

    2.13 Operators and punctuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.14 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

    Outline of Programming with C

    46 3.2 Unary Operators ........................................................................................................... 50 3.3 Relational and Logical Operators .......................

    C# 语言规格说明(English Edition第五版)

    7.16.1 Ambiguities in query expressions 216 7.16.2 Query expression translation 216 7.16.2.1 Select and groupby clauses with continuations 217 7.16.2.2 Explicit range variable types 217 7.16.2.3 ...

    论文研究-Temporal Operators Over Unary and Binary Events.pdf

    单元和双元事件上的时间算子研究,王昊,冯铃,金融市场,传感器,网络流量监控的应用产生了大量,连续的,具有时间顺序的流数据。处理流数据需要高完善的时间检测技术。受到当

    iso-iec 14496-10(3rd_2006-03-01)_MPEG4_AVC_H264.pdf

    1 Scope ............................................................................................................................................................................ 1 2 Normative ...

    python3.6.5参考手册 chm

    Operators And Special Methods Builtins Build and C API Changes Performance Porting To Python 3.0 What’s New in Python 2.7 The Future for Python 2.x Changes to the Handling of Deprecation ...

    Unary Negation - 2013 (1309.2069)-计算机科学

    1–46 www.lmcs-online.orgSubmitted Jan. 16, 2013 Published Sep. 24, 2013UNARY NEGATIONBALDER TEN CATE a AND LUC SEGOUFIN ba UC Santa Cruz e-mail address: btencate@ucsc.edub INRIA and ENS Cachan, LSV ...

    Spread Unary Coding (1412.6122)-计算机科学

    Spread Unary CodingSubhash Kak1Abstract Unary coding is useful but it is redundant in its standard form. Unary coding can also be seen as spatial codingwhere the value of the number is determined by ...

    ARM® Compiler v5.06 for µVision® armasm User Guide

    7.19 Unary operators 7.20 Binary operators 7.21 Multiplicative operators 7.22 String manipulation operators 7.23 Shift operators 7.24 Addition, subtraction, and logical operators 7.25 Relational ...

    深入理解计算机系统(英文版)

    1 Introduction 1 1.1 Information isBits inContext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Programs areTranslated byOtherPrograms intoDifferent Forms . . . . . . . . . ....

    unary_minus.rar_version control

    Display a printable version of a control character.

    Unary:帝国时代2的社区AI

    将Unary.ai和Unary.per复制到scripts文件夹,此文件夹取决于您的AoE安装。 开始帝国时代。启动Unary.exe。在文本框中输入“帝国时代”进程名称,然后单击“连接到进程”按钮。输入一元的播放器编号,然后单击“开始...

    Unary层1

    初始例代码初始例代码输张量形状 (1,1,3,3)from cuda import cudartimport tensorrt as trtconfig.max

Global site tag (gtag.js) - Google Analytics