You are previewing C++ 2013 for C# Developers, Second Edition.
O'Reilly logo
C++ 2013 for C# Developers, Second Edition

Book Description

"

C++ 2013 for C# Developers provides a fast-track to C++ proficiency forthose already using the C# language at an advanced level. Beginning with a detailed explanation of the mechanics of C++'s execution sequence, its grammar, syntax and data access you'll quickly learn the similarities and differences between C++ and C#.

The second and third partsof the of the book are devoted to a detailed deep-dive into C++ development to provide clear information and advice about how to use the languageeffectively.

"

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. Foreword
  8. About the Author
  9. About the Technical Reviewer
  10. Acknowledgments
  11. Preface
  12. Introduction
  13. Part 1: Fast Track to C++
    1. Chapter 1: Hello, World
      1. Starting the Visual Studio 2013 Console
      2. Retrieving the Source Files
      3. Executing HelloCpp.cpp
      4. A Quick Tour of the Visual C++ IDE
        1. Understanding Projects and Solutions
        2. Understanding the Differences
        3. Window Layout
        4. Building, Executing, and Debugging
      5. Summary
    2. Chapter 2: There’s No Place Like Home
      1. Developing the Program
        1. Deal Me In
        2. The Completed C# Program
        3. A Quick Look at the Code
      2. Projects and Solutions
        1. A Quick Look
        2. Building and Executing the Project
        3. Binding C++
      3. Doing the Shuffle Without the IDE
        1. Basic Command-Line Compilation
        2. Using a Module
      4. Summary
    3. Chapter 3: Syntax
      1. Keywords and Separators
        1. C# class (Reference Type)
        2. C# struct (Value Type)
        3. Caveat
        4. Lack of Locality
      2. The C++ Approach
      3. Types of Member Access Operators
      4. Keyword Differences
      5. Arrays and Functions
        1. The Conversion Operators
        2. Memory Allocation
        3. Accessibility and Visibility
      6. Properties, Events, and Delegates
        1. Generics
        2. Built-in Types
      7. Summary
    4. Chapter 4: C# to C++/CLI
      1. Converting a C# Application
        1. Add the Keyword namespace After using
        2. Add the Punctuator ^ to the Reference Type Declarations
        3. Modify the Built-in Types
        4. Change the Array Declarations and Type Parameters
        5. Change the Enumeration Declarations
        6. Change the Object Allocations and Instantiations
        7. Change the Pass by Reference Parameters
        8. Change the Class Member Access Operators for Handles
        9. Change the Separators for Namespaces and Static Accesses
        10. Change the Class Declarations
        11. Add the Function main()
      2. Summary
    5. Chapter 5: Tools
      1. Lutz Roeder’s .NET Reflector
        1. What Is Reflection?
        2. Installing and Loading .NET Reflector and the C++/CLI Add-in
        3. Executing .NET Reflector
      2. Instant C++
      3. Tools Shipped with Visual Studio
        1. Microsoft .NET Framework IL Disassembler (ILDasm)
        2. Dependency Walker (Depends)
      4. More Visual Studio Tools
      5. Summary
    6. Chapter 6: Data Types
      1. C# Types versus C++ Types
        1. The C++ struct Keyword
        2. Native Classes
      2. Value Types and Reference Types
        1. Dynamic Memory Pools
        2. Garbage Collection
        3. Initialization
        4. Boxing
      3. Constructor Forwarding
      4. C# Partial Classes
      5. Reference Types on the Stack
      6. Basic Types
        1. Basic Type Differences
        2. Missing Keywords
        3. Marshaling Required
      7. Summary
    7. Chapter 7: Arrays
      1. Native Arrays
      2. Managed Arrays
        1. A Simple Example
        2. Arrays as Parameters and Return Values
        3. A Sophisticated Example
        4. Higher Dimensional Arrays
      3. Native Arrays
      4. Summary
    8. Chapter 8: Polymorphism and Protection
      1. Polymorphism
        1. Inheritance
        2. Interfaces
        3. Abstract Classes
        4. Sealed Classes
        5. Static Classes
      2. Methods
        1. Virtual Methods
        2. Working with Methods
        3. Virtual Methods Summary
        4. Accessing Base Class Fields and Methods
      3. Protection Mechanisms
        1. Visibility
        2. Accessibility
        3. Inheritance
        4. Declaring ref struct and ref class
        5. Overload Resolution
        6. Hide by Name and Hide by Signature
      4. Summary
  14. Part 2: Details
    1. Chapter 9: Pointers and Unsafe Code
      1. The C# View: A Blessing and a Curse
        1. Pointers: A Definition and a Caveat
        2. Valid Targets and Syntax
        3. Common Pointer Operators
        4. Example of Pointer Usage
        5. Verifiable Code and Pointer Usage in C#
        6. Side Effects of Writing Unsafe Code
        7. Pointer Usage in C++
        8. Verifiable Code in C++
        9. C++ Handles
        10. C++/CLI Address Operators
        11. Complex Examples
        12. Nightmares
      2. Summary
    2. Chapter 10: Properties and Events
      1. A Basic Example Using Properties in C#
      2. A Basic Example Using Properties in C++/CLI
      3. A Look Inside the Grammar
      4. Trivial Properties
        1. Syntax
        2. Example
      5. Indexed Properties
        1. Syntax
        2. Example
        3. Default Indexed Properties
      6. C# Properties
        1. Scalar Properties in C#
        2. Indexed Properties in C#
      7. Advanced Properties of Properties
        1. Read-Only and Write-Only Properties
        2. Static Properties
        3. Virtual Properties
        4. Abstract and Sealed Properties
        5. Named Overriding
        6. Property Protection Mechanisms
      8. Property Caveats
      9. Miscellaneous Property Details
      10. Events and Delegates
      11. Delegates
        1. Sorting
      12. Multicast Delegates
      13. Instance Delegates
      14. Events
        1. Trivial Events
        2. Nontrivial Events
      15. Summary
    3. Chapter 11: Expressions and Operators
      1. Operator Overloading
        1. Complex Numbers, a Basic Example
        2. A Mathematical Diversion: Numbers Modulo Primes
        3. Implicit and Explicit Conversions of Built-in Types
        4. User-Defined Conversions
        5. CLS-Compliant Operators
      2. Summary
    4. Chapter 12: The End of the Beginning
      1. Include Files
        1. Forward Declarations
        2. The Problem
        3. The Solution
        4. Include File Caveats
        5. Types of Declarations
      2. Scope Resolution Operator
      3. Nullable Types
        1. Examples in C# and C++/CLI
        2. The ?? Operator in C#
        3. Under the Hood
      4. Checked Expressions
      5. Anonymous Methods
      6. Context-Sensitive Keywords
      7. Method Group Conversion
      8. Constructor-Initialized Variables
      9. Expression Statements with No Effect
      10. Exceptions
        1. Basic Exception Handling
        2. Function-Try Blocks
      11. Summary
    5. Chapter 13: Fun, Fun, and More Fun
      1. Dropping Light Bulbs
        1. Initial Thoughts
        2. A Rough Approximation
        3. A Little Algebra
        4. Discovering a Recursive Algorithm
        5. Implementation
        6. First Drop
      2. Bridge Crossing
        1. Background
        2. Algorithm and Implementation
        3. The Code
        4. Taking the Algorithm for a Spin
      3. Dealing with Cannibals
        1. Assumptions
        2. The Code
      4. Summary
  15. Part 3: Advanced Concepts
    1. Chapter 14: Generics
      1. A Queue of Tasks
        1. C# Implementation Under .NET 1.0
        2. Moving to Generics
        3. Creating Generic Classes in C++/CLI
      2. Summary
    2. Chapter 15: Introduction to Templates
      1. Comparison with Generics
        1. Syntactic Differences
        2. Comparison Summary
        3. Compilation Process
        4. Templates Don’t Really Exist
        5. Constraining Freedom Is a Good Thing
        6. The Template Paradigm
      2. Specialization
        1. Partial Specialization
        2. Partial Ordering of Function Templates
        3. Nontype Template Parameters
      3. Complex Numbers
        1. Overview
        2. Mathematical Formulas
        3. Generic Implementation
        4. Templates to the Rescue
      4. Core Differences: Templates and Generics
      5. Summary
    3. Chapter 16: Advanced Generics and Casts
      1. Constraints
        1. Kinds of Constraints
        2. Type Constraints
        3. Satisfying Type Constraints
        4. The gcnew Constraint
        5. The value class Constraint
        6. The ref class Constraint
        7. Constraints Summary
      2. Cast Operators
        1. Runtime Type Identification
        2. const_cast<>()
        3. static_cast<>()
        4. dynamic_cast<>()
        5. reinterpret_cast<>()
        6. safe_cast<>()
        7. An Adder
        8. Generic Delegates
      3. Summary
    4. Chapter 17: The Preprocessor
      1. C# Preprocessor Commands
        1. Code Regions
        2. Conditional Code Compilation
      2. C++ Preprocessor Commands
        1. Full Text Substitution Language
        2. Debugging Support
        3. Function Syntax
        4. Concatenation Operator
        5. String Operator
        6. Macros on Macros
        7. Special Preprocessor Predefined Macros
        8. #define
        9. #undef
        10. Conditional Directives
        11. #include
        12. #using
        13. #error
        14. #pragma
        15. Some Useful Pragmas
      3. Summary
    5. Chapter 18: Native C++
      1. The iostream Library
        1. Pointers to Members
        2. Operators new and delete
        3. /Zc:forScope
        4. /Zc:wchar_t
        5. Default Parameters
      2. C++ Runtime Library Functions
        1. stdio.h
        2. stdlib.h
        3. Other Include Files
      3. STL
        1. vector
        2. deque
        3. list
        4. auto_ptr
      4. Summary
    6. Chapter 19: Multiple Language Support
      1. .NET Language Integration
        1. Gathering Metadata
        2. Tracking Students Example
      2. .NET Interoperability
        1. Wait for the Beep
        2. C# Platform Invoke
        3. C++ Built-in Support
        4. Using C++ for C# InterOp
      3. Summary
    7. Chapter 20: Final Thoughts
      1. Standard Dispose Pattern
        1. Destructors and Finalizers
        2. Implementation in C#
        3. Implementation in C++/CLI
        4. For Further Study
      2. Function Objects
      3. Special Pointers
        1. Interior Pointers
        2. Pinning Pointers
      4. Templates Revisited
      5. Class Hierarchy Pitfalls
      6. Type Aliases (typedef)
      7. Friends
      8. Volatile Data
      9. Constant and Mutable Data
      10. Attributes
      11. Summary
  16. Index