일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Protocol
- Regular Expression
- Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- Decorator
- Python Code
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- t1
- Python Implementation
- 프로그래머스
- 43. Multiply Strings
- Substring with Concatenation of All Words
- 컴퓨터의 구조
- attribute
- data science
- shiba
- 315. Count of Smaller Numbers After Self
- Class
- 밴픽
- 파이썬
- Generator
- 715. Range Module
- concurrency
- 시바견
- iterator
- DWG
- LeetCode
- 운영체제
- Python
Archives
- Today
- Total
Scribbling
[C++] Interface 본문
#include <iostream>
using namespace std;
class Printable {
friend ostream& operator<<(ostream& os, const Printable& obj);
public:
virtual void print(ostream& os) const = 0;
virtual ~Printable() {}
};
ostream& operator<<(ostream& os, const Printable& obj) {
obj.print(os);
return os;
}
class class1 : public Printable {
public:
virtual void print(ostream& os) const override {
os << "class1" << endl;
}
};
class class2 : public Printable {
public:
virtual void print(ostream& os) const override {
os << "class2" << endl;
}
};
int main() {
class1 cls1;
class2 cls2;
cout << cls1 << endl;
cout << cls2 << endl;
}
'Computer Science > C++' 카테고리의 다른 글
[C++] LRU Cache (2) | 2024.10.05 |
---|---|
[C++] Object Oriented Programming (0) | 2024.10.01 |
[C++] Strings (0) | 2024.09.30 |
[C++] Abstract Class, Polymorphism (0) | 2024.09.28 |
[C++] Virtual Functions (0) | 2024.09.28 |