250x250
Notice
Recent Posts
«   2024/07   »
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
관리 메뉴

일상 코딩

[C++/9.07] 괄호"()" 연산자 오버로딩과 함수 객체 Functor 본문

C++/따배C++ 09강 연산자 오버로딩

[C++/9.07] 괄호"()" 연산자 오버로딩과 함수 객체 Functor

polarcompass 2021. 10. 30. 01:56
728x90
#include<iostream>
using namespace std;

class Accumulator
{
private:
    int m_counter = 0;

public:
    int operator () (int i)
    {
        return (m_counter += i);
    }
};

int main()
{
    Accumulator acc;

        // functor
    cout << acc(10) << endl;
    cout << acc(20) << endl;

    return 0;
}
728x90