Thread: overloading with typedef

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    184

    overloading with typedef

    Is it possible to make this work somehow (without adding an extra parameter or doing two separate functions)?

    Code:
    //I didn't create this but am stuck using it
    typedef long jint;
    
    void doSomething(jint a)
    {
         ...do something with a jint...
    }
    
    void doSomething(long a)
    {
         ...do something with a different with a long...
    }

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Not a chance. Why would you want that anyway? Microsoft does similar in their API for equally unfathomable reasons.

    Example:
    Code:
    struct jint { long dummy; };
    struct kint { long dummy; };
    Thus making two incompatible types... But I know you have no control over jint. Why would you do such a thing?

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by 6tr6tr View Post
    Is it possible to make this work somehow (without adding an extra parameter or doing two separate functions)?
    You could make jint an actual class which does nothing except wrap the integer. That way it would be a distinct type from long. It would be a pain, with very little benefit. I'd just name the two functions two different names and live with the hackishness.

    typedefs are supposed to create aliases of types. They don't create distinct types which otherwise act exactly like each other. It's not the intention.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM