달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

#include <iostream>
using namespace std;

class Point
{
private:
 int xpos, ypos;
public:
 Point(int x=0, int y=0) : xpos(x), ypos(y)
 {
  cout<<"Point 객체 생성"<<endl;
 }
 ~Point()
 {
  cout<<"Point 객체 소멸"<<endl;
 }
 void SetPos(int x, int y)
 {
  xpos=x;
  ypos=y;
 }
 friend ostream& operator<<(ostream& os, const Point& pos);
};
ostream& operator<<(ostream& os, const Point& pos)
{
 os<<'['<<pos.xpos<<", "<<pos.ypos<<']'<<endl;
 return os;
}

class SmartPtr
{
private:
 Point * posptr;
public:
 SmartPtr(Point * ptr) : posptr(ptr)
 {  }

 Point& operator*() const
 {
  return *posptr;
 }
 Point* operator->() const
 {
  return posptr;
 }
 ~SmartPtr()
 {
  delete posptr;
 }
};

int main(void)
{
 SmartPtr sptr1(new Point(1, 2));
 SmartPtr sptr2(new Point(2, 3));
 SmartPtr sptr3(new Point(4, 5));
 cout<<*sptr1;
 cout<<*sptr2;
 cout<<*sptr3;

 sptr1->SetPos(10, 20);
 sptr2->SetPos(30, 40);
 sptr3->SetPos(50, 60);
 cout<<*sptr1;
 cout<<*sptr2;
 cout<<*sptr3;
 return 0;
}

 

====================================

 

 

#include <iostream>
using namespace std;

class Point
{
private:
 int xpos, ypos;
public:
 Point(int x=0, int y=0) : xpos(x), ypos(y)
 {  }
 Point operator+(const Point & pos) const
 {
  return Point(xpos+pos.xpos, ypos+pos.ypos);
 }
 friend ostream& operator<<(ostream& os, const Point& pos);
};

ostream& operator<<(ostream& os, const Point& pos)
{
 os<<'['<<pos.xpos<<", "<<pos.ypos<<']'<<endl;
 return os;
}

class Adder
{
public:
 int operator()(const int &n1, const int &n2)
 {
  return n1+n2;
 }
 double operator()(const double &e1, const double &e2)
 {
  return e1+e2;
 }
 Point operator()(const Point &pos1, const Point &pos2)
 {
  return pos1+pos2;
 }
};

int main(void)
{
 Adder adder;
 cout<<adder(1, 3)<<endl;
 cout<<adder(1.5, 3.7)<<endl;
 cout<<adder(Point(3, 4), Point(7, 9));
 return 0;
}

 

 

=============

 

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
 string str1="I like ";
 string str2="string class";
 string str3=str1+str2;

 cout<<str1<<endl;
 cout<<str2<<endl;
 cout<<str3<<endl;

 str1+=str2;
 if(str1==str3)  
  cout<<"동일 문자열!"<<endl;
 else
  cout<<"동일하지 않은 문자열!"<<endl;

 string str4;
 cout<<"문자열 입력: ";
 cin>>str4;
 cout<<"입력한 문자열: "<<str4<<endl;
 return 0;
}

 

 

 

 

 

Posted by C언어 보이
|

운수 좋은 날

글짖기 2014. 10. 20. 08:37

 

오늘은 운수 좋은 날

너구리 삼형제를 잡았네

착하게 사니깐 이런 복이 다 있네

 

너구리 맏형 왈

집에 두고 온 마누라는 어떡하지

저 농부는 이런 내 마음을 알까

Posted by C언어 보이
|

 

http://jimnong.tistory.com/321

 

 

 

Posted by C언어 보이
|