Appendix A Quick Reference - Pdf 63

355
■ ■ ■
APPENDIX
Quick Reference
T
his appendix covers the new keywords introduced in C++/CLI, specifies which are also reserved
words, and defines and lists contextual keywords and whitespaced keywords. This appendix
includes a reference table for features available in native, mixed, pure, and safe modes. You’ll
also find a summary of the syntax introduced in C++/CLI.
Keywords and Contextual Keywords
Some new keywords were introduced in the C++/CLI bindings. Many new keywords introduced
in C++/CLI are sensitive to the context in which they are used, so as to avoid creating new reserved
words in order not to interfere with existing identifiers. When used in the proper syntactic position,
contextual keywords are interpreted with the keyword meaning. When used in any other posi-
tion, they may be used as identifiers. This enables your code to continue to use a variable that
happens to collide with a C++/CLI contextual keyword without any special marking or modifi-
cation. This also enables C++/CLI to use keywords that otherwise would be common variable
names. There are several new keywords that are not contextual, as described in Table A-1: gcnew,
generic, and nullptr. Table A-2 shows the new contextual keywords.
Table A-1. C++/CLI Keywords
Keyword Description Usage
gcnew Allocates instances of reference
types on the garbage-collected
(managed) heap
R^ r = gcnew R();
generic Declares a parameterized type
(generic) that is recognized by
the runtime
generic <typename T> ref class G { /* ... */ };
nullptr Evaluates to the null value for
a pointer, indicating an

try/catch block.
finally { /* ... */ }
in Used in the for each statement. for each (R^ r in collection)
{ /* ... */ }
initonly Specifies a field that can only be
modified in a constructor.
initonly int i;
internal Specifies that access to a member
is restricted to within an assembly.
public ref class R
{ internal: void f(); }
literal Specifies a value that is a
literal constant.
literal int SIZE = 150;
override Indicates that a function is intended
to be a virtual override of the base
class function of the same name.
virtual int f(int a, int b) override;
property Declares a field-like member
on a type.
property int P;
sealed Indicates a type that cannot be used
as a base class or a method cannot
be overridden.
virtual int f(int a, int b) sealed;
where Used in the declaration of generics
to specify constraints on the types
that may be used as type arguments
for a generic type or function.
generic <typename T> where T : R

for each (R^ r in collection) { /* ... */ }
interface class Declares an interface with
all members public
interface class I { /* ... */ };
interface struct Declares an interface with
all members public
interface struct I { /* ... */ };
ref class Declares a managed type
with private default
accessibility
ref class R { /* ... */ };
ref struct Declares a managed
struct with public
default accessibility
ref struct S { /* ... */ };
value class Declares a value type
with private default
accessibility
value class V { /* ... */ };
value struct Declares a value type
with public default
accessibility
value struct S { /* ... */ };
Hogenson_705-2AppA.fm Page 357 Wednesday, October 18, 2006 5:16 PM
358
APPENDIX

QUICK REFERENCE
switch( __identifier(switch) )
{

Copyright (C) Microsoft Corporation. All rights reserved.
Hogenson_705-2AppA.fm Page 358 Wednesday, October 18, 2006 5:16 PM
APPENDIX

QUICK REFERENCE
359
detecting_clr.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
/out:detecting_clr.exe
detecting_clr.obj
C:\code\appendix>detecting_clr
Must be compiling with /clr...
C:\ code\appendix>cl detecting_clr.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
detecting_clr.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
/out:detecting_clr.exe
detecting_clr.obj
C:\ code\appendix>detecting_clr
Not compiling with /clr.
XML Documentation
XML files may be generated from code comments written in the CLR XML doc format by writing
comments in the format in code and compiling with the /doc compiler option. You can use
these XML files to generate formatted documentation. The tool xdcmake.exe is used to generate
the XML files from doc comments. Table A-4 lists the XML tags available.
Table A-4. XML Doc Comment Reference
XML Tag Description

/// <para>You can break the comments into paragraphs.
/// <see cref="R::G"/> for related information.</para>
/// <seealso cref="R::G"/>
/// </summary>
void F(int i) {}
<para>text</para> Defines a paragraph
<param>description</param> Describes a function parameter
<paramref name="name"> Specifies a hyperlink to
the parameter
<permission cref="member"> Specifies access (e.g., public)
<remarks>description</remarks> Specifies the detailed description
<returns>description</returns> Specifies the return
value information
<see cref="member"> Specifies a cross-reference
<seealso cref="member"> Lists additional references
<summary>text</summary> Specifies text that gives a
brief synopsis
<value>description</value> Specifies a property description
Table A-4. XML Doc Comment Reference (Continued)
XML Tag Description
Hogenson_705-2AppA.fm Page 360 Wednesday, October 18, 2006 5:16 PM
APPENDIX

QUICK REFERENCE
361
/// The method G is a method in the R class.
/// <summary>Counts the number of characters in two strings.</summary>
/// <param name="s1"> Description for s1</param>
/// <param name="s2"> Description for s2</param>
/// <returns>The sum of the length of two strings.</returns>

<member name="T:R">
Ref class R demonstrates XML Documentation Comments.
<summary> A class demonstrating documentation comments </summary>
<remarks> A detailed description of R goes into the remarks block
</remarks>
</member>
</members>
</doc>
Hogenson_705-2AppA.fm Page 361 Wednesday, October 18, 2006 5:16 PM
362
APPENDIX

QUICK REFERENCE
It is up to you to then render this in the desired user-friendly documentation format. For
example, you could generate documentation in various formats using a tool such as Sandcastle,
available from the Microsoft download center ( />Summary of Compilation Modes
This book has covered many aspects of the various modes, but not all. Table A-5 summarizes
the features available in each compilation mode.
Table A-5. Features Available in Various Compilation Modes
Feature Native Mixed Pure Safe
Define and use native types Yes Yes Yes No
Define and use managed types No Yes Yes Yes
Define native functions Yes Yes No No
Define managed functions No Yes Yes Yes
Native instructions* Yes Yes No No
Managed instructions (IL) No Yes Yes Yes
Build 32-/64-bit
agnostic assemblies
No No No Yes
Use the NET Framework No Yes Yes Yes


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status