Kafin nutsewa cikin cikakkun bayanai game da amfani da aikin 'inline' a cikin C++, ya zama dole a fahimci manufar ayyuka gabaɗaya a fagen C++. Aiki toshe ne na lamba wanda ke yin takamaiman aiki kuma an ƙirƙira shi da gaske don sake amfani da lambar. C++, kasancewar ƙarin yaren C yana da duk fasalulluka na C da ƙari ƙarin sabbin abubuwa kamar azuzuwan, abubuwa da ayyuka. Daga cikin waɗannan, manufar aikin 'inline' ya fito fili idan ana maganar inganta aiwatar da shirin.
Tare da wannan fahimtar a zuciya, muhimmiyar rawar 'layin layi' shine rage farashin kira zuwa ƙananan ayyuka. Yana da kyau a faɗi cewa lokacin da aka kira wani aiki, an haɗa wani adadin sama da ƙasa. Wannan sama-sama ya haɗa da adana mahimman bayanai da sarrafawar da aka tura zuwa aikin da aka kira. Amma, tare da aikin 'cikin layi', mai tarawa kawai yana maye gurbin kiran aiki tare da lambar aiki mai dacewa, don haka yana kawar da saman aikin kiran aiki. Wannan yana zuwa tare da fa'idar ingantacciyar gudu ko aikin lambar, musamman don ƙananan ayyuka.
#include
amfani da sunaye std;
nunin layi mara amfani(){
cout << "Aikin Layi a cikin C++" << endl; } int main(){ nuni (); dawo 0; } [/code] Misalin da ke sama yana gabatar da aikin 'launi' mai sauƙi a cikin C++. Maɓallin 'inline' yana sanar da mai tarawa don saka kwafin jikin aikin kowane wuri da ake kira aikin.
Ma'anar Ayyukan Layi
Kalmar 'layi' tana nuna sanya layi. Ana sanya ma'anar aikin 'inline' a wurin da ake kiran aikin, kamar fadada macro a cikin C++. Wannan yana nuna cewa abin da aka haɗa a lokacin kiran aiki ya lalace saboda babu buƙatar tsalle zuwa wani wuri sannan a dawo, yayin da ake sanya jikin aikin cikin aikin kiran.
Lokacin amfani da Aikin Layi?
Aikin 'inline' tabbas kayan aiki ne mai ƙarfi, amma yakamata a yi amfani da shi cikin adalci. Babban manufarsa ita ce ƙara saurin aiwatarwa ta hanyar guje wa wuce gona da iri na kiran ayyuka wanda gabaɗaya yana da fa'ida ga ƙananan ayyuka. Don manyan ayyuka, haɓakar ƙayyadaddun lambar da yuwuwar haɓaka girman shirin na iya fin fa'ida. Hakanan yana da mahimmanci a tuna cewa ayyana aiki azaman 'layi' baya nufin mai tarawa zai yarda dashi. Babban yanke shawara ya rage ga mai tarawa.
Rarraba Lambobin Ayyukan Layi
Idan muka dawo kan misalin da aka bayar, bari mu rarraba kowane sashe na lambar C++ da ta ƙunshi aikin 'inline'.
[lang code="C++"]
#include
amfani da sunaye std;
Layukan farko guda biyu na lambar suna sanar da mai tarawa game da ɗakunan karatu don amfani da su.
nunin layi mara amfani(){
cout << "Aikin Layi a cikin C++" << endl; } [/code] Wannan ɓangaren lambar shine inda aka ayyana aikin 'inline'. Anan, `void` yana nufin nau'in aikin dawowa wanda ba komai bane, sai kuma sunan aikin 'nuni()'. A ciki, ana buga sako. [code lang = "C++"] int main () { nuni (); dawo 0; } [/code] A cikin aikin `babban()`, ana kiran aikin `nuna()'. Da yake aikin 'inline' ne, mai tarawa zai maye gurbin wannan kiran aikin - `nuni()` tare da ma'anar aikin layi. Wannan yana ba da hangen nesa gabaɗaya kan ra'ayi da amfani da ayyukan 'layi' a cikin C++ tare da ainihin misali na aiwatarwa.
Laburare da Ayyuka a C++
A cikin misalin da ke sama, mun yi amfani da `
Idan ya zo ga ayyuka, akwai manyan nau'ikan nau'ikan C++: ginanniyar ayyuka da fayyace ayyukan mai amfani. Ayyukan da aka gina, kuma aka sani da ayyukan laburare an riga an bayyana su kuma suna zuwa tare da mai tarawa. Ƙayyadaddun ayyuka na mai amfani, kamar yadda sunan ke nunawa, mai amfani ya bayyana shi yayin shirin.
a ƙarshe, aikin 'inline' wata dabara ce ta haɓakawa da ake amfani da ita da farko don haɓaka aikin aiwatar da shirye-shirye ta hanyar kawar da abin da ake samarwa yayin kiran aiki. Fahimtar lokacin da za a yi amfani da ayyukan 'layin layi' na iya zama kayan aiki mai mahimmanci ga mai tsara shirye-shiryen C++ kuma ana iya amfani da shi don sa lambar ta gudana cikin sauri da inganci.