일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- attribute
- Class
- 30. Substring with Concatenation of All Words
- 프로그래머스
- 컴퓨터의 구조
- concurrency
- Protocol
- DWG
- Python Implementation
- LeetCode
- 315. Count of Smaller Numbers After Self
- 시바견
- Decorator
- t1
- 109. Convert Sorted List to Binary Search Tree
- shiba
- 43. Multiply Strings
- 파이썬
- Python Code
- Substring with Concatenation of All Words
- 운영체제
- data science
- kaggle
- Regular Expression
- Python
- Generator
- iterator
- 715. Range Module
- Convert Sorted List to Binary Search Tree
- 밴픽
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 |