Thread: how to add new operator

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    how to add new operator

    hy
    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

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    I dont think it is possible to create your own operators in C++.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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

  4. #4
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by romrubiens
    hy
    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
    You need to make a swap function, hun. You really can't create your own operators, I don't believe.

  5. #5
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    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;
    }
    Last edited by Krak; 02-27-2005 at 04:08 PM.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Or you can use the std::swap found in <algorithm>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 10:53 PM
  3. help writing function definitions
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2003, 09:44 PM
  4. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  5. Overriding = operator.
    By Strahan in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2001, 03:26 PM