Thread: create user define literal?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    create user define literal?

    In C++ there are a number of primitives that are not defined in terms of other types. By this I'm thinking

    int a = 1;
    char b = 'M';
    float c = 3.45f;
    short d = 0xC3A3;

    Is it possible to define your own literal? What I would like to do is have a hex literal for a data type where n = sizeof(data_type). If this type were a big integer, then I would want something like:

    BigInt e = 0x13CA9B0C98D983E912DA0B0A9F87E0;

    My goal is to assign a value from one contingous chunk of bytes and to not do it with a string.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is possible if you are compiling with respect to C++11. I have never tried this feature myself, but it was not too difficult to find a tutorial that might work for you.
    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. How to create a compound literal for maximum compatibility
    By Richardcavell in forum C Programming
    Replies: 3
    Last Post: 03-23-2011, 07:07 AM
  2. Create a user library
    By mabuhay in forum C Programming
    Replies: 8
    Last Post: 11-03-2005, 03:42 PM
  3. user define function
    By jeevanvoon in forum C Programming
    Replies: 1
    Last Post: 10-14-2004, 04:28 AM
  4. user define function trouble!
    By johnnypiere in forum C++ Programming
    Replies: 2
    Last Post: 10-16-2002, 12:31 AM
  5. Help! Sample prog. on user-define string functions
    By orbandjay in forum C++ Programming
    Replies: 6
    Last Post: 08-17-2002, 02:48 AM