Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
OverloadFunc
//g++ 7.4.0 //////////////////////////////////////////////////////////////////////////// //OverloadFunc: understanding overloading of function call operator, operator() //this code is created by Rezaul Hoque on July 06,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <algorithm> class Demo{ int x,y; public: int total=0; Demo(){} Demo(int a,int b){x=a;y=b;} Demo(Demo&c){x=c.x;y=c.y; std::cout<<"\nCopy constructor is in work\n"; } Demo& operator=(const Demo& c) { if (this==&c) return *this; if(this != &c) { x=c.x; y=c.y; } std::cout<<"\nCopy assignment is in work\n"; return *this; } Demo(Demo&& t ){ std::cout<<"Move constructor is in work\n"; x=std::move(t.x); y=std::move(t.y); } Demo& operator=(Demo&& ot) { if (this==&ot) return *this; if (this != &ot) { x=std::move(ot.x); y=std::move(ot.y); } std::cout<<"Move assignment is in work\n"; return * this; } int getX(){return x;} int getY(){return y;} void operator ()(int w,int z){ total += w*z;} double operator()(double t){ return total*t+total;} }; int main() { Demo e1(0,0); Demo e2,e3; std::cout<<"Overloading function call operator: \n"; e1(10,5); double tot=e1(0.5); std::cout<<e1.total; std::cout<<"\nSecond overloaded function call operator:\n"<<tot; e2=e1; std::cout<<"\ne2.x :"<<e2.getX()<<"e2.y :"<<e2.getY(); e3=Demo(e1); std::cout<<"\ne3.x :"<<e3.getX()<<"e3.y :"<<e3.getY(); std::cout<<"\ne1.x :"<<e1.getX()<<"e1.y :"<<e1.getY(); return 0; }
run
|
edit
|
history
|
help
0
Breakfast
Shultz_Lab1.CPP
SpiralMatrix
sort
vertical sum
Stream5
Testul 11(2021)
doubly
Radix sort
asa