Skip to Content
C++ How to Program, 10/e
book

C++ How to Program, 10/e

by Paul Deitel, Harvey Deitel
February 2016
Beginner
1080 pages
207h 57m
English
Pearson
Content preview from C++ How to Program, 10/e

19.2 Self-Referential Classes

A self-referential class contains a member that points to a class object of the same class type. For example, the definition


class Node {
public:
   explicit Node(int); // constructor
   void setData(int); // set data member
   int getData() const; // get data member
   void setNextPtr(Node*); // set pointer to next Node
   Node* getNextPtr() const; // get pointer to next Node
private:
   int data; // data stored in this Node
   Node* nextPtr; // pointer to another object of same type
};

defines a type, Node. Type Node has two private data members—integer member data and pointer member nextPtr. Member nextPtr points to an object of type Node—an object of the same type as the one being declared here, hence the term self-referential ...

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.
Start your free trial

You might also like

C++ How to Program, Sixth Edition

C++ How to Program, Sixth Edition

P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.
C++ How to Program, Ninth Edition

C++ How to Program, Ninth Edition

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9780134448930Purchase book