O'Reilly logo

Imperfect C++ Practical Solutions for Real-Life Programming by Matthew Wilson

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

Member variables (also known as fields) are data that are part of an object or, in the case of static member variables, belong to a class. Methods are functions that belong to object instances or, in the case of static methods, to a class. Several modern languages (C#, D, Delphi) support the concept of a property. Though using a property is syntactically the same as accessing member variables, properties are different to C++ member variables in that using them may actually involve a function call. For example, property definitions might look like[1] the Date class shown in Listing 35.1.

Example 35.1. 

 class Date { public: enum WeekDay { Sunday, Monday, ... }; public: property WeekDay get_DayOfWeek() const; property int get_DayOfMonth() ...

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