Skip to content

Instantly share code, notes, and snippets.

@kogemrka
Created November 23, 2011 16:24
Show Gist options
  • Save kogemrka/1389118 to your computer and use it in GitHub Desktop.
Save kogemrka/1389118 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <list>
#include <set>
class Point
{
public:
Point()
{
x = y = 0;
}
Point(int _x, int _y)
{
x = _x;
y = _y;
}
Point(const Point &p)
{
x = p.x;
y = p.y;
}
/*Point operator*(int num)
{
Point res;
res.x = x * num;
res.y = y * num;
}*/
friend std::ostream& operator<<(std::ostream &out, const Point &p);
friend Point operator*(int num, Point p);
private:
int x, y;
};
std::ostream& operator<<(std::ostream &out, const Point &p)
{
out << "(" << p.x << ", " << p.y << ")";
}
Point operator*(int num, Point p)
{
Point res;
res.x = p.x * num;
res.y = p.y * num;
return res;
}
Point operator*(const Point& p, int num)
{
return num * p;
}
Point operator*=(Point& p, int num)
{
return num * p;
}
int main()
{
std::list<int> v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v1.push_back(4);
v1.push_back(5);
v1.push_back(6);
std::set<int> s1;
s1.insert(4);
s1.insert(5);
s1.insert(6);
s1.insert(1);
s1.insert(2);
s1.insert(3);
// std::cout << v1[0] << v1[1] << v1[2] << std::endl;
for (std::list<int>::iterator it = v1.begin(); it != v1.end(); ++it)
std::cout << *it;
std::cout << std::endl;
for (std::set<int>::iterator it = s1.begin(); it != s1.end(); ++it)
std::cout << *it;
std::cout << std::endl;
Point myPoint(1, 1);
// myPoint.x = 1; myPoint.y = 1;
myPoint = myPoint * 10;
std::cout << myPoint << std::endl;
return 0;
}
/*
int Point::getx()
{
return x;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment