O'Reilly logo

Ivor Horton's Beginning Visual C++ 2013 by Ivor Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required