Chapter 7Defining Your Own Data Types
- How structures are used
- How classes are used
- The basic components of a class and how you define class types
- How to create and use objects of a class
- How to control access to members of a class
- How to create constructors
- The default constructor
- References in the context of classes
- How to implement the copy constructor
You can find the wrox.com code downloads for this chapter on the Download Code tab at www.wrox.com/go/beginningvisualc. The code is in the Chapter 7 download and individually named according to the names throughout the chapter.
THE STRUCT IN C++
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 at first, but as you’ll see in this chapter, an object can be just an instance of one of your own data types.
A structure is a user-defined type that you define using the struct
keyword so it is often referred to as a struct. The struct
originated back in C 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 used today, so you really ...
Get Ivor Horton's Beginning Visual C++ 2013 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.