Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PrePostIncrOp
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////// //PrePostIncrOp: understanding overloading of preincrement and postincrement 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;} Demo operator++(){ x=x+10; y=y+10; return *this; } Demo operator++(int){ x=x+5; y=y+5; return *this; } 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<<"After preincrement operator\n"; std::cout<<"\ne1.x :"<<e1.getX()<<" e1.y :"<<e1.getY(); std::cout<<"\ne2.x :"<<e2.getX()<<" e2.y :"<<e2.getY(); e3=e1++; std::cout<<"After postincrement operator\n"; std::cout<<"\ne1.x :"<<e1.getX()<<" e1.y :"<<e1.getY(); std::cout<<"\ne3.x :"<<e3.getX()<<" e3.y :"<<e3.getY(); return 0; }
run
|
edit
|
history
|
help
0
3SUM problem
Preference List
Jilebi Nimki
Make BinTree
EN WU WU
https://rextester.com/TXKE53925
template
sort
Making pyramid using nested loop 1/2
RegexMatch