Thread: defining operators

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    defining operators

    how can i define an operator ?

    i have do define the prod operator with 2 predicates (lq (<=) and neg (!=))
    how can i do that ?
    if it is a stupid question sorry!

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    if im understanding you correctly, you want to define how a
    cetain operator will act on two variables of some form. This is
    called operator overloading and isn't contained in c, but it is in
    c++. I may be misinterpretting you though.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    yes. how can i do that in c++ ? sorry but the ambiguesness of the question but the one who asked it was a little ambigous

  4. #4
    Registered User
    Join Date
    Feb 2006
    Location
    Sydney, Australia
    Posts
    40
    Quote Originally Posted by spank
    yes. how can i do that in c++ ? sorry but the ambiguesness of the question but the one who asked it was a little ambigous
    If you are using C++, wouldn't that be better asked in the C++ forum?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Moved to C++

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    http://www.cplusplus.com/doc/tutorial/classes2.html

    If you don't like that one, just google for "Operator Overloading' - there's a lot of 'em

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Just to clarify for you though. There is no way to "define" an operator. This meaning to say you're creating an operator that doesn't exist. C++ has a set list of operators which you can not change the number of arguments of or the precedence of. Overloading operators is creating more functionality for C++ defined operators to suit the needs of user defined datatypes.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. Defining operators
    By Lynux-Penguin in forum C++ Programming
    Replies: 3
    Last Post: 10-01-2002, 08:03 AM