일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- C
- API
- 윈도우즈
- 투자
- OOP
- beans
- 포인터
- Kafka
- array
- windows
- meta
- Call-by-reference
- Sort
- HTML
- CLASS
- c++
- function
- UTF-8
- jsp
- 노드
- CSS
- 자료구조
- System
- 악성코드
- java
- algorithm
- request
- WebProgramming
- query
- JavaScript
- Today
- Total
hahahia
Operator Overloading(연산자 오버로딩) 본문
/* made by hahahia */
#include <iostream>
#include <string>
using namespace std;
class Student{
friend istream &operator >> (istream &, Student &); /* Operator overloading(input, output) */
friend ostream &operator << (ostream &, const Student &);
public:
string getName() const { return Name; } /* Get Function */
int getNumber() const { return Number; }
private:
string Name; /* student name, number */
int Number;
};
istream &operator >> (istream & in, Student & stu){
cout << "student name : ";
in >> stu.Name;
cout << "student number : ";
in >> stu.Number;
return in;
}
ostream &operator << (ostream & out, const Student & stu){
out << "Student Name : " << stu.Name << "\n"
<< "Student Number : " << stu.Number << "\n" ;
return out;
}
int main(){
Student stu1;
cout << "input Student Name and Number\n";
cin >> stu1;
cout << stu1;
cout << "getFunction Student Name : " << stu1.getName() << "\n"
<< "getFunction Student Number : " << stu1.getNumber() << "\n";
}
실행결과
'Language > C++' 카테고리의 다른 글
C++ 상속(inheritance) (0) | 2012.09.01 |
---|---|
C++ 포함 (0) | 2012.09.01 |
1주차 (0) | 2011.06.27 |
Class GradeBook Using an Array to Store Grades (0) | 2011.05.25 |
재귀함수를 이용한 fibonacci (0) | 2011.05.17 |