devxlogo

Make an Object Appear Like a Pointer

Make an Object Appear Like a Pointer

You can make an object appear like a pointer with a smart pointer. If a class overloads the operator ->( ), then any object of that class can appear like a pointer when the operator ->( ) is called. The following program illustrates this:

#include "iostream.h"class test{public :void fun( ){cout ( ){return &t ;}} ;void main( ){smartpointer sp ;sp -> fun( ) ;}

The beauty of overloading operator ->( ) is that even though sp is an object, you can make it work like a pointer. The operator ->( ) returns the address of the object of the type test. Using this address of the test object the function fun( ) of the class test gets called. Thus even though fun( ) is not a member of smartpointer class, you can still call it using sp.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist