Q:

C++ function chain returning function

First of all sorry for the not so clear title, it is far easier to explain it with code:
Given a function prototype like this:
auto sum(int a){
      ... 
}

I want to be able to use it in this way:
add(3) == 3 //true
add(1)(2)(3) == 6 //true

I'm just trying to do this for personal knowledge, so I would appreciate more if someone would indicate me which constructs I should study to achieve this (I'm pretty sure I have to use std::function, but I don't know how) , rather than giving me the plain solution. 
Thank you all in advance.  

A:

May not be exact answer, but you can try this way:
class foo {
    int data = 0;
public:
    foo& operator()(int i) { data += i; return *this; }
    bool operator==(int i) { return this-> data == i; }
    void print() const { cout << data << endl; }
};

int main() {

    foo add;
    add(1)(2)(3);
    add.print();
    cout <<  (add(3) == 9 ?   "Same" : "Not same") << endl;
}

