Overloading Function Call Operator ( )




This video tutorial explains how to overload the function call operator ( ) in c++.
You are gonna learn what are the special operators available in c++ for overloading, how to overload array function call operator, what are the important things to remember when overloading function call operator in detail with example.

source code for this tutorial

#include <iostream>

using namespace std;
class Marks{
int mark;
public:
    Marks(int m){
        cout << "constructor is called"<<endl;
    mark = m;
    }

    void whatsYourMark(){
    cout << "hey i got "<< mark <<" marks" << endl;
    }

    Marks operator()(int mk){
        mark = mk;
         cout << "operator function is called"<<endl;
        return *this;
    }

};
int main()
{
    Marks anilsmark(85);
    anilsmark.whatsYourMark();

    anilsmark(44);
anilsmark.whatsYourMark();
    return 0;
}

 
Back To Top