Skip to content

Instantly share code, notes, and snippets.

@madbence
Created April 29, 2013 13:48
Show Gist options
  • Save madbence/5481665 to your computer and use it in GitHub Desktop.
Save madbence/5481665 to your computer and use it in GitHub Desktop.
#include <iostream>
template <class T>
class Vektor
{
protected:
T x;
T y;
public:
Vektor(const T& x = T(), const T& y = T()) : x(x), y(y) { } //Default konstruktor
Vektor(const Vektor&); //Copykonstruktor
T GetX() { return x; } //
T GetY() { return y; }
Vektor& operator=(const Vektor&); //operaotr=
Vektor operator+(const Vektor&); //operator+
Vektor operator-(const Vektor&); //operator-
bool operator==(const Vektor&); //operator== halmaznál kell
bool operator<=(const Vektor&); //operator<= úgyszint
template <class U>
friend std::ostream& operator<<(std::ostream&, const Vektor<U>&); //2Dvektor kiírása
};
///Copykonstruktor
template <class T>
Vektor<T>::Vektor(const Vektor& v1)
{
x = v1.x;
y = v1.y;
}
///operator=
template <class T>
Vektor<T>& Vektor<T>::operator=(const Vektor& v1)
{
return Vektor(v1.x, v1.y);
}
///operator+
template <class T>
Vektor<T> Vektor<T>::operator+(const Vektor& v1)
{
return Vektor(x+v1.x, y+v1.y);
}
///operator-
template <class T>
Vektor<T> Vektor<T>::operator-(const Vektor& v1)
{
return Vektor(x-v1.x, y-v1.y);
}
///operator== halmaznál kell
template <class T>
bool Vektor<T>::operator==(const Vektor& v1)
{
return (x == v1.x && y == v1.y);
}
///operator<= úgyszint
template <class T>
bool Vektor<T>::operator<=(const Vektor& v1)
{
if (x <= v1.x)
return true;
else if (y <= v1.y)
return true;
else
return false;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const Vektor<T>& h1)
{
os << "(" << h1.x << " , " << h1.y << ")"; //(x , y)
return os;
}
template <class T>
class Vektor_3D : public Vektor<T>
{
protected:
T z;
public:
Vektor_3D(const T& x = T(), const T& y = T(), const T& z = T()) : Vektor<T>(x, y), z(z) { } //Default konstruktor
Vektor_3D(const Vektor_3D&); //Copykonstruktor
Vektor_3D& operator=(const Vektor_3D&); //operator=
Vektor_3D operator+(const Vektor_3D&); //operator+
Vektor_3D operator-(const Vektor_3D&); //operator-
bool operator==(const Vektor_3D&); //operator== halmaznál kell
bool operator<=(const Vektor_3D&); //operator<= úgyszint
template <class U>
friend std::ostream& operator<<(std::ostream&, const Vektor_3D<U>&); //2Dvektor kiírása
};
///Copykonstruktor
template <class T>
Vektor_3D<T>::Vektor_3D(const Vektor_3D& v1) : Vektor<T>(v1), z(v1.z) { }
///operator=
template <class T>
Vektor_3D<T>& Vektor_3D<T>::operator=(const Vektor_3D& v1)
{
}
///operator+
template <class T>
Vektor_3D<T> Vektor_3D<T>::operator+(const Vektor_3D& v1)
{
return Vektor_3D<T>(this->x+v1.x, this->y+v1.y, z+v1.z);
}
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment