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
initonlyfields 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 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, so ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access