Monday, 26 April 2021

Inline Function of a class in C++ Qus: 2

 Inline function and classes in C++:


All the functions defined inside the class are implicitly inline. 



class A

{

public:

    inline int square(int a) 

    {

       return a*a;

    }

};

int main() {

    A ob;

   cout<<ob.square(6);

}



Explicitly Defined:


class A

{

public:

    int square(int a) ;

    

};


inline int A:: square(int a)

{

     return a*a;

}

int main() {

    A ob;

   cout<<ob.square(6);

}

No comments:

Post a Comment