View Poll Results: Is this a dumb question?

Voters
11. You may not vote on this poll
  • Yes!

    4 36.36%
  • No.

    7 63.64%

Thread: typedef/overloaded operators

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    typedef/overloaded operators

    Hi, just felt curious about this one thing (sorta spur of the moment pointless idea). Can you overload the operators for basic data types like int? And if so, if you made a typedef of an int for example and called it "mytype", could you overload an operator for int and also overload the same operator for mytype, differently?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Can you overload the operators for basic data types like int?
    Nope not possible. If overloading basic or primitive datatypes would be possible every programmer could introduce a new basic datatype. Problem: Ambiguous.
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Oh right
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    No, and no.

    Operators involving only primitive types are set in stone, and cannot be changed.

    Also, a typedef is not a new type, it's only "shorthand". The true type will always be substituted during compilation.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yeah, that was what I thought, but it was a sort of sudden "what if" idea that I felt might be worth exploring since I wasn't 100% sure
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Just FYI, enums are technically not the same as ints (even though they're the same internally), so you can overload an enum differently from an int.

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm, so I can have 2 different int "types", with one of them overloadable?...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    You could make an Integer class or something... why would you WANT to overload the operators of an int, actually?

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, no real reason... out of idle curiosity I guess I enjoy coming up with far-out and useless theories that
    #ifdef SOME_CONDITION
    should work
    #else
    usually don't
    #endif
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Originally posted by Hunter2
    Well, no real reason... out of idle curiosity I guess I enjoy coming up with far-out and useless theories that
    #ifdef SOME_CONDITION
    should work
    #else
    usually don't
    #endif
    It's all about the types. C++ is very strongly typed. It's designed so that you can use the type system to help you catch errors and debug code. The fact that an enum and an int are fundamentally the same doesn't matter: the type is different.

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Ok, thanks. Lots of useful facts pouring in here
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 07:17 AM
  2. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  3. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 04:37 AM
  4. increment and decrement operators
    By ee0u22ba in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2003, 04:57 AM
  5. Operators
    By George in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 07:35 PM