Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class B {
- int a;
- public:
- B(): a(0) {}
- B(int a): a(a) {}
- void print() {
- std::cout << a << std::endl;
- }
- friend void f1() {
- std::cout << "aa" << std::endl;
- }
- friend void f2(B& b) { // 함수 정의도 friend
- B b1{};
- b1.a = 10;
- std::cout << b1.a << std::endl;
- }
- friend void f3(); // 함수 선언만 friend
- friend B operator+(const B& b1, const B& b2) {
- return {b1.a + b2.a};
- }
- };
- void f3() {
- B b;
- std::cout << b.a << std::endl;
- }
- int main() {
- B b;
- // f1(); // 해당 함수 찾을 수 없음
- f2(b);
- f3();
- B b1(10), b2(20);
- B b3 = b1 + b2;
- b3.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement