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

references;- https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm

static member function in c++ in hindi

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

1 thought on “Static member function in C++ in Hindi – with example”

  1. bhaiya mujhe static data member of a class ke notes provide kar sakte ho kyaa kyuki ye to ek fun. ko dusra fun. kese access kr sakta hai ye btaya gya h but mujhko chahiye ki ek class ke variable ko statically declare karke kese access kiya jae . agar ap ek se do din me send kedenge to meherbaani hogi sir kyuki mere exams start hone wale h or is topic me agr que. aye to mere 8 marks ni milenge pls help.

    Reply

Leave a Comment