devxlogo

Accessing Static Class Members

Accessing Static Class Members

Because static class members are not associated with a particular object of their class, you can access them even if you haven’t instantiated any object. In the following example, the static member function read_val() returns the value of the static member n, although no instance of class C exists:

 class C{private: static int n;public: static int read_val() {return n;}};int main(){ int m = C::read_val(); // no object of type C exists; OK}
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