C++'ın güçlü nesne yapısı

/*
Sanki sadece java nesne tabanlı dil gibi gösterilir. Halbuki c++ dili sürekli kendini güncel tutan java ve c nin güçlü yanlarını alan bir dildir. Yeni standartların gelmesiyle python dilinden de çok şey almıştır. Bazen yeni dillerde bile görmediğim yapıları bu dile olan hayranlığımı her seferinde arttırıyor.
Bu dilinde kendisine ait yazma şekli vardır. bu yazma şeklini öğrenirsek oldukça yüksek hızla çalışan uygulamalar yapabiliriz. Bu dille çalışırken hiçbir teknoloji firmasına tam bağlamıyor olmakta beni iyi hissettiriyor. örnek .net dilleri Microsofta göbekten bağlanıyorsunuz. Yada java açık kaynak olsa da OpenJDK Oracle gibi değil.
*/
//c++ oldukça güçlü nesne tabanlı ve Generic bir dildir. işte //kanıtı. Daha c++ yeni özelliklerini kullanmadım bile
typedef struct dot { double x, y; } dot;
template <class T>
class point
{
public:
point() = default;
point() { x = y = 0; }
point(const T& x1 = 0, const T& y1 = 0) : x{ x1 }, y{ y1 } {}
point(T&& x1, T&& y1) : x{ x1 }, y{ y1 } {}
point(const point& p1)
{
x = p1.x; y = p1.y;
}
~point()
{
}
T getx() { return x; }
T gety() { return y; }
void setx(const T& v) { x = v; }
void sety(const T& v) { y = v; }
const point& operator+(const point& p1) { const point& sum = point( p1.x + this->x,p1.y + this->y ); return sum; }
friend istream &operator>>(istream &input, point &D) {
input >> D.x >> D.y;
return input;
}
friend std::ostream& operator<<(std::ostream& out, const point& p) //outstream can't be const or second referance. it always changing
{
out << "(" << p.x << "," << p.y << ")";
return out;
}
private:
double x, y;
};
typedef point<double> pointd;
typedef point<int> pointi;
typedef point<long> pointl;
typedef point<short> points;
void uygula_creating_types() {
pointd a{ 2.3,2.4 }, b{3.7,5.9};
cout << "a =" << a << " b=" << b << endl;
cout << "sum =" << a + b<<endl;
std::getchar();
}

Yorumlar

Popüler Yayınlar