Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство_по_C++_CLI.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
8.1 Mб
Скачать

11. Classes and Functions 242

11.1   Returning a Class Type 242

11.1.1   Returning a Tracking Reference 242

11.1.2 Practical Learning: Introducing Data Reading 243

11.1.3 Returning a Handle 244

11.1.4 Practical Learning: Returning a Handle 244

11.2 Passing a Class Type 246

11.2.1   Passing a Tracking Reference 246

11.2.2 Passing a Handle 248

11.2.3 Practical Learning: Passing a Handle 248

11.2.4 The Effect of Passing a Class as a Tracking Reference or as a Handle 250

11.2.5 Passing a Handle as a Reference 252

11.3 Using the String Class 254

11.3.1   Returning a String 254

11.3.2 Passing a String 254

11.4 Introduction to the Methods of a Class 256

11.4.1   Methods Fundamentals 256

11.4.2 Practical Learning: Introducing Methods 256

11.4.3 Method Local Definition 257

11.4.4 Practical Learning: Implementing a Method Locally 258

11.4.5 Method Global Definition 259

11.4.6 Practical Learning: Implementing Methods Globally 260

11.4.7 Inline Methods 262

11.5 Class and Self Return 264

11.5.1 Introduction 264

11.5.2 this Pointer 265

11.5.3 Practical Learning: Using the this Pointer 266

12. Classes and their Methods 268

12.1   Methods and Parameters  268

12.1.1 Methods Arguments 268

12.1.2 Practical Learning: Introducing Data Reading 268

12.1.3 Constant Arguments 269

12.1.4 Practical Learning: Passing Constant Arguments 271

12.1.5 Private Methods 274

12.1.6 Protected Methods 275

12.2 Static Members of a Class 276

12.2.1   Static Member Variables 276

12.2.2 Static Methods 277

12.3 Classes and Constants 281

12.3.1   Static Constants 281

12.3.2 Literal Constants 283

12.4 Class Nesting 284

12.4.1 Introduction 284

12.4.2 Implementing Methods of a Nested Class 287

13. Class Construction and Destruction 290

13.1   Class Construction 290

13.1.1   Method Initializer 290

13.1.2 Practical Learning: Introducing Constructors 292

13.1.3 Default Constructor 294

13.1.4 Practical Learning: Using the Default Constructor 296

13.1.5 The Constructor Initializer 296

13.1.6 Practical Learning: Initializing Using the Default Constructor 297

13.1.7 Constructor Overloading 298

13.1.8 Practical Learning: Overloading the Constructor 300

13.1.9 Techniques of Initializing With a Constructor 305

13.1.10 Practical Learning: Initializing With the Constructors 307

13.2 The Copy Constructor 309

13.2.1   Copying an Object 309

13.2.2 Using a Copy Constructor 309

13.3 Destructors 311

13.3.1 Introduction 311

13.3.2 Practical Learning: Creating a Destructor 311

13.3.3 Object Destruction in the Native Heap 312

13.3.4 Object Destruction and the Managed Heap 312

14. The Properties of a Class 315

14.1 Properties Fundamentals 315

14.1.1 Introduction 315

14.1.2 Practical Learning: Introducing the Properties of a Class 315

14.1.3 Reference Methods 317

14.1.4 A Property 319

14.2 Types of Properties 320

14.2.1   Simple Properties 320

14.2.2 Practical Learning: Creating Simple Properties 321

14.2.3 Read-Only Properties 323

14.2.4 Practical Learning: Using Read-Only Properties of a Class 325

14.2.5 Write-Only Properties 327

14.2.6 Read/Write Properties 329

14.2.7 Practical Learning: Using Read/Write Properties of a Class 331

14.3 Other Techniques of Implementing Properties 335

14.3.1   Static Properties 335

14.3.2 A Class Property 336

14.3.3 A Property as a Handle 336

14.3.4 Inheriting a Property 336