devxlogo

Access a Class Member Function Without Creating a Class Object

Access a Class Member Function Without Creating a Class Object

In some cases, it is possible to call a class member function without creating the class object.

In the following example, the program will print “hello world” although class A has never been created. When the program enters the “PrintMe” function, the “this” pointer is zero. This is fine as long as you don’t access data members through the “this” pointer.

#include class A {public:	void PrintMe();};void A::PrintMe(){    printf("Hello World
");}void main(){A* p = 0;p-
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
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