Static member function in C++ in Hindi – with example

हेल्लो दोस्तों! आज हम इस post में Static member function in C++ in Hindi (स्थैतिक मेम्बर फंक्शन क्या है?) के बारें में पढेंगे और इसके example को भी देखेंगे. तो चलिए start करते हैं:-

Static member function in C++ in Hindi

Static member function को create करने के लिए हमें function को declare करते समय static कीवर्ड का प्रयोग करना पड़ता है.

जब भी किसी member function को static के रूप में declare किया जाता है तो वह class के objects पर depend (निर्भर) नहीं होता.

हम एक static member function को object और dot operator (.) का प्रयोग करके invoke कर सकते हैं परन्तु हमें static members को invoke करने के लिए class name और scope resolution operator : : का प्रयोग करना चाहिए.

static member functions केवल static data members और दूसरे static member functions को access कर सकते हैं. ये class के non-static data members और member functions को एक्सेस नहीं कर सकते.

Drawbacks of static member functions  – इसकी कमियाँ

  • इनके पास this pointer नहीं होता है.
  • static member function जो है वह virtual नहीं हो सकता.

Static member function का example –

#include <iostream>
using namespace std;
class S
{
static int i;
public:
static void init(int x)
{
i = x;
}
void show()
{
cout <<i;
}
};

int S::i;
int main()
{
S::init(150); 
S x;
x.show();
return 0;
}

इसका आउटपुट –
150

निवेदन:- अगर आपके लिए यह आर्टिकल उपयोगी रहा हो तो इसे अपने friends और classmates के साथ अवश्य share कीजिये. और आपको इसके बारें में और पता हो या कही पर mistake हो तो उसे कमेंट करके बताइए. Thanks.

Leave a Comment