Home » C++ programming language

What is self-referential class in C++?

Learn: What are self-referential classes in C++ programming language, why they are important for development purpose?

It is a special type of class. It is basically created for linked list and tree based implementation in C++. If a class contains the data member as pointer to object of similar class, then it is called a self-referential class.

Consider the following class declaration

class node
{
	private:
		int data;
		node * next;  //pointer to object of same type

	public:
		//Member functions.
};

In this declaration, the statement node *next; represents the self-reverential class declaration, node is the name of same class and next the pointer to class (object of class).

Normally, we use self referential structure for linked list or tree based implementation. But OOPS is always better choice for development. Structures and classes are both user define data-types. But classes provide encapsulation, inheritance and other good feature they help us to manage large code. Because at project level, it is very important to manage code properly.






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.