U E D R , A S I H C RSS

삼총사Cpp Study/20030806

오늘 한 것

vector 소스

~cpp 
#include <iostream> 
using namespace std; 

class CVector
{ 
private: 
	int x;
	int y;
public: 
	CVector(); 
	CVector(int a, int b); 
	CVector operator+(CVector a);
	void SetValue(int a, int b);
	int GetX();
	int GetY();
};
ostream & operator<<(ostream &os, CVector &a);

CVector::CVector() 
{ 
	x = 0; 
	y = 0; 
} 
CVector::CVector(int a, int b) 
{ 
	x = a; 
	y = b; 
} 
CVector CVector::operator+(CVector a) 
{ 
	CVector temp;
	temp.SetValue(x + a.GetX(), y + a.GetY());
	return temp;
} 
void CVector::SetValue(int a, int b)
{
	x = a;
	y = b;
}
int CVector::GetX()
{
	return x;
}
int CVector::GetY()
{
	return y;
}
ostream & operator<<(ostream & os, CVector &a)
{
	os << "x: " << a.GetX() << "   y: " << a.GetY() << endl;
	return os;
}

int main() 
{
	CVector v1(50, 100);
	CVector v2(22, 33);
	CVector v3 = v1.operator +(v2);
	cout << "--v1값--" << endl;
	cout << v1 << endl;
	cout << "--v2값--" << endl;
	cout << v2 << endl;
	cout << "--v3값--" << endl;
	cout << v3 << endl;
	return 0; 
} 

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:39
Processing time 0.0133 sec