Chapter 7. Defining Your Own Data Types
This chapter is about creating your own data types to suit your particular problem. It's also about creating objects, the building blocks of object-oriented programming. An object can seem a bit mysterious to the uninitiated but, as you will see in this chapter, an object can be just an instance of one of your own data types.
In this chapter, you will learn about:
Structures and how they are used
Classes and how they are used
The basic components of a class and how you define class types
Creating and using objects of a class
Controlling access to members of a class
Constructors and how to create them
The default constructor
References in the context of classes
The copy constructor and how it is implemented
How C++/CLI classes differ from native C++ classes
Properties in a C++/CLI class and how you define and use them
Literal fields and how you define and use them
initonly
fields and how you define and use themWhat a static constructor is
The struct in C++
A structure is a user-defined type that you define using the keyword struct
, so it is often referred to as a struct. The struct
originated back in the C language, and C++ incorporates and expands on the C struct
. A struct
in C++ is functionally replaceable by a class insofar as anything you can do with a struct
you can also achieve by using a class; however, because Windows was written in C before C++ became widely used, the struct
appears pervasively in Windows programming. It is also widely used today, ...
Get Ivor Horton's Beginning Visual C++®2008 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.