Thread: User-defined types to built in types

  1. #1
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    308

    User-defined types to built in types

    Hey!

    Is it possible to have an user-defined type behave exactly like another type, the other type being a built-in type? Every reference to the user-defined type in code is to be treated as a different type (in my case, a built-in type).

    So, if I have:
    Code:
    Foo <T>
    it should behave exactly like T does as in the default behaviour in every statement of code involving type Foo<T> is treated as T. Reason for this is that if I provide additional functionality to class Foo, I can have default behaviour of T along with that additional functionality.
    Last edited by Zeus_; 12-30-2019 at 09:28 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The normal way is to simply ditch Foo and provide additional functionality for the built-in type by means of functions.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 10-09-2016, 12:28 PM
  2. Replies: 3
    Last Post: 04-14-2012, 09:14 AM
  3. conflicting types for built-in function
    By BIOS in forum C Programming
    Replies: 5
    Last Post: 09-12-2011, 01:41 PM
  4. Stl lists and user defined types
    By figa in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2005, 12:09 PM
  5. external user defined types
    By doubleanti in forum C++ Programming
    Replies: 6
    Last Post: 12-16-2001, 04:07 PM

Tags for this Thread