Bu Blog doğru zamanda, doğru yerde, doğru kodları kullanalım diye yaratıldı!
15 Mart 2016 Salı
C++'Da This işaretçisi kullanımı
C++'da This-> işaretçisi Non-Static (Statik olmayan) üyelerde kullanılabilir.
Örnek Kod :
#include <iostream>
#include <string>
using namespace std;
class ornek1{
private :
int x;
public :
ornek1(void){
x=0;
} //!Constructor Fonksiyon (Parametre Almayan)
int getX() //!!x private oldugu icin publicde bulunan bir fonksiyon yardımıyla x e ulasiriz
{
return x;
}
};
class ornek2{
private :
int x;
public : ornek2(){
this->x=0;
}
int getX()
{
return x;
}
};
int main(void)
{
ornek1 test1;
ornek2 test2;
cout << test1.getX() << endl; //0 çıktısı verir
cout << test2.getX() << endl; //0 çıktısı verir
}
Ekran Çıktısı :
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder