Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,321 of 33,346    |
|    MARH to All    |
|    Class to behave like ints    |
|    07 May 14 17:11:32    |
      From: marhardwick@googlemail.com              I have a need for a class to be used as a type of ID, say an ID for       apples, I also need another class for IDs for oranges, another for       pears and so on. I also need it to be the case that you cannot assign       an apple ID to a pear ID. For example:              AppleID a(7); // ID for an apple.       AppleID b;              b = a; // Allowed.              PearID p(5); // ID for a pear obviously.              b = p; // Oops, not allowed. Would like to be a compile error.              I recall reading about a templated class that gave this behaviour,       where some sort of signature differentiated between what effectively       were the same class. Unfortunately my memory has failed me and my       googling skills are inadequate. Does anyone have suggestion or can       point me in the right direction?              Thank you.                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca