Skip to main content

Posts

Showing posts with the label This pointer

Short notes on : 1. static data members and static member functions 2. This pointer 3. Namespaces

 1. Static data members and static member functions:     Static data members and static member functions are used in C++ to create class variables and functions that are shared by all objects for the class. A static data member is a variable that is associated with the class, not with any individual object of that class. Similarly, a static member function is a function that is associated with the class and can be called without an object of that class. Syntax for declaring static data members and static member functions: class MyClass { public:     static int myStaticData; // static data member     static void myStaticFunction(); // static member function }; int MyClass::myStaticData = 0; // static data member definition void MyClass::myStaticFunction() { // static member function definition     // implementation } 2. This pointer: The this pointer is a pointer that holds the memory address of the current object. It is a keyword in C++ that ...