C++ Concept Map

Data Members

An object may contain values which are stored internally and are unique to that object. In order to do this, each value needs an appropriate declaration as a data member in the class. A data member may be of any type, including classes already defined, pointers to objects of any type, or even references to objects of any type.

Data members may be private or public, but are usually held private so that values may only be changed at the discretion of the class function members. In the example below, the class C contains two a private data member of type int, and a public data member of type pointer to char.

class C {
private:
   int x;
public:
   float f;
};

Please mail any corrections and/or suggestions to Roger Hartley at
rth@cs.nmsu.edu

Copyright © 2003 Roger Hartley