O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Foundations of C++/CLI: The Visual C++ Language for .NET 3.5

Book Description

Foundations of C++/CLI: The Visual C++ Language for .NET 3.5 introduces C++/CLI, Microsoft's extensions to the C++ syntax that allow you to target the common language runtime, the key to the heart of the .NET Framework 3.5. This book gives you a small, fast-paced primer that will kick-start your journey into the world of C++/CLI. In 13 no–fluff chapters, Microsoft insiders take readers into the core of the C++/CLI language and explain both how the language elements work and how Microsoft intends them to be used.

This book is a beginner's guide, but it assumes a familiarity with programming basics. And it concentrates on explaining the aspects of C++/CLI that make it the most powerful and fun language of the .NET Framework. As such, this book is ideal if you're thinking of migrating to C++/CLI from another language. By the end of this book, you'll have a thorough grounding in the core language elements together with the confidence to explore further that comes from a solid understanding of a language's syntax and grammar.

What you'll learn

  • The basics of C++/CLI

  • The object–oriented features of C++/CLI

  • How C++/CLI sits within the .NET Framework 3.5

  • How to create C++/CLI programs

  • Using STL/CLR

Who this book is for

Developers wanting to learn C++/CLI.

Table of Contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. Foreword by Brandon Bray
  6. Foreword to the First Edition by Stanley B. Lippman
  7. Foreword by Herb Sutter
    1. A Design Rationale for C++/CLI
  8. About the Author
  9. About the Technical Reviewer
  10. Acknowledgments
  11. Introduction
    1. Why C++/CLI?
    2. C++/CLI As a .NET Language
    3. About This Book
  12. CHAPTER 1 Introducing C++/CLI
    1. Garbage Collection and Handles
    2. The /clr Compiler Option
    3. The Virtual Machine
    4. The Common Type System
    5. The CLI and the .NET Framework
    6. "Hello, World"
    7. Native and Managed Types in the Same Program
    8. Summary
  13. CHAPTER 2 A Quick Tour of the C++/CLI Language Features
    1. Primitive Types
    2. Aggregate Types
    3. Reference Classes
    4. Value Classes
    5. Enumeration Classes
    6. Interface Classes
    7. Elements Modeling the "has-a" Relationship
    8. Generics
    9. The STL/CLR Library
    10. Summary
  14. CHAPTER 3 Building C++/CLI Programs for the Common Language Runtime with Visual C++
    1. Targeting the CLR with Visual C++
    2. Visual C++ Compilation Modes
    3. Caveats When Upgrading Code to Visual C++ 2005 or 2008
    4. Architecture Dependence and 64-bit Programming
    5. Assemblies and Modules
    6. The Assembly Manifest
    7. The #using Directive
    8. Referencing Assemblies and Access Control
    9. Friend Assemblies
    10. Assembly Attributes
    11. The Linker and the Assembly Linker
    12. Resources and Assemblies
    13. Signed Assemblies
    14. Multifile Assemblies
    15. C++/CLI in the Visual Studio Development Environment
    16. Summary
  15. CHAPTER 4 Object Semantics in C++/CLI
    1. Object Semantics for Reference Types
    2. Object Semantics for Value Types
    3. Implications of the Unified Type System
    4. Implicit Boxing and Unboxing
    5. Stack vs. Heap Semantics
    6. The Unary % Operator and Tracking References
    7. Dereferencing Handles
    8. Copy Constructors
    9. Lvalues, GC-Lvalues, Rvalues, and GC-Rvalues
    10. auto_handle
    11. Parameter Passing
    12. Summary of Parameter-Passing Semantics
    13. Do's and Don'ts of Returning Values
    14. Summary
  16. CHAPTER 5 Fundamental Types: Strings, Arrays, and Enums
    1. Strings
    2. Input/Output
    3. System::String and Other I/O Systems
    4. Arrays
    5. Enumerated Types
    6. Summary
  17. CHAPTER 6 Classes and Structs
    1. Constructors and Initialization
    2. Static Constructors
    3. Copy Constructors for Reference and Value Types
    4. Literal Fields
    5. initonly Fields
    6. Const Correctness
    7. Properties, Events, and Operators
    8. Example: A Scrabble Game
    9. The this Pointer
    10. Access Levels for Classes
    11. Native and Managed Classes
    12. Class Destruction and Cleanup
    13. Finalizers
    14. Summary
  18. CHAPTER 7 Features of a .NET Class
    1. Properties
    2. Using Indexed Properties
    3. Delegates and Events
    4. Events
    5. Operator Overloading
    6. Summary
  19. CHAPTER 8 Inheritance
    1. Name Collisions in Inheritance Hierarchies
    2. Abstract Classes
    3. Sealed Classes
    4. Virtual Properties
    5. Special Member Functions and Inheritance
    6. Casting in Inheritance Hierarchies
    7. Summary
  20. CHAPTER 9 Interfaces
    1. Interfaces vs. Abstract Classes
    2. Declaring Interfaces
    3. Interfaces Implementing Other Interfaces
    4. Interfaces with Properties and Events
    5. Interface Name Collisions
    6. Interfaces and Access Control
    7. Interfaces and Static Members
    8. Literals in Interfaces
    9. Commonly Used .NET Framework Interfaces
    10. Interfaces and Dynamically Loaded Types
    11. Summary
  21. CHAPTER 10 Exceptions, Attributes, and Reflection
    1. Exceptions
    2. What's in an Exception?
    3. Creating Exception Classes
    4. Using the Finally Block
    5. Dealing with Exceptions in Constructors
    6. Throwing Nonexception Types
    7. Attributes
    8. Reflection
    9. Application Domains
    10. Summary
  22. CHAPTER 11 Parameterized Functions and Types
    1. Generics
    2. Type Parameters
    3. Generic Functions
    4. Generic Types
    5. Generic Collections
    6. Using Constraints
    7. .NET Framework Container Types
    8. Managed Templates
    9. Summary
  23. CHAPTER 12 An Introduction to the STL/CLR Library
    1. A First Look at the STL/CLR Library
    2. STL and STL/CLR Basic Ideas
    3. STL/CLR Terminology and Naming Conventions
    4. STL/CLR Container Types
    5. Value Types and Reference Types in an STL/CLR Container
    6. STL/CLR Iterators
    7. STL/CLR Algorithms
    8. The STL/CLR deque Type
    9. Other STL/CLR Containers
    10. Anatomy of a Vector
    11. Using STL/CLR Across Assembly Boundaries
    12. STL/CLR Function Objects and Delegates
    13. Working with STL/CLR Containers and .NET Collections
    14. Summary
  24. CHAPTER 13 Interoperability
    1. The Many Faces of Interop
    2. Interoperating with Other .NET Languages
    3. Using Native Libraries with Platform Invoke
    4. The Marshaling Library
    5. Using Native Libraries Without P/Invoke
    6. Recompiling a Native Library As Managed Code
    7. Interop with COM
    8. Interior Pointers
    9. Pinning Pointers
    10. Native Objects and Managed Objects
    11. Native and Managed Entry Points
    12. Managed and Native Exceptions
    13. Summary
  25. APPENDIX Quick Reference
    1. Keywords and Contextual Keywords
    2. Detecting CLR Compilation
    3. XML Documentation
    4. Summary of Compilation Modes
    5. Syntax Summary
  26. Index