hy :cool:
how can i add a new operator something like <=> which will swap two operands on its LHS and RHS..
dont tell me abt operator overloading..as compilerdoesnt has the defination of this operator..
thanks
Printable View
hy :cool:
how can i add a new operator something like <=> which will swap two operands on its LHS and RHS..
dont tell me abt operator overloading..as compilerdoesnt has the defination of this operator..
thanks
I dont think it is possible to create your own operators in C++.
Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
You might also want to read the posting guidelines:
http://cboard.cprogramming.com/annou...ouncementid=51
Remember, too, that the board has a search facility, a link is at the top of your screen. It will often get you a quicker answer to your questions than waiting for a response to one you have posted.
If you have any questions about this you may ask or you can contact one of our forum leaders:
http://cboard.cprogramming.com/showgroups.php
You need to make a swap function, hun. You really can't create your own operators, I don't believe.Quote:
Originally Posted by romrubiens
Code:void swap(int *val1,int *val2){
int temp=*val1;
*val1=*val2;
*val2=temp;
}
int main(){
int x=5; int y=2;
swap(&x,&y);
cout << "X = "<<x<<" and Y= "<<y<<endl;
return 0;
}
Or you can use the std::swap found in <algorithm>