Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!samsung!uunet!apctrc!zmls04 From: zmls04@trc.amoco.com (Martin L. Smith) Newsgroups: comp.lang.c++ Subject: Re: Transparent int class (we second the problem) Message-ID: Date: 18 Oct 90 18:02:26 GMT References: Sender: news@trc.amoco.com Distribution: comp Organization: Amoco Production Company, Tulsa Research Center Lines: 45 In-reply-to: matthew@hydra.ua.oz.au's message of 15 Oct 90 09:20:53 GMT In article matthew@hydra.ua.oz.au (Matthew Donaldson) writes: I am not sure that this can be done in C++, but I am trying to make a class that looks exactly like an int (or as much so as possible), but inside works differently. I want an integer that is protected against concurrent reads and writes, but still looks like an int. So each operation would use mutual exclusion primitives to protect against concurrent assignment, etc. The aim is to be able to do something like this: ProtectedInt a; ... a= 2; cout << "Now a is " << a << "\n"; and everything else you can do with ints, such as a |= 2, fn(a), int b= a, ProtectedInt b=a, etc. [ as an aside, how are operations like |= handled? There is no operator|= ] I can do most of these - the main exception is the actual using of the class to return an int - that is, just using the "a" variable, and making it look like an int. I haven't found any way of doing this, and have had to be content with a.Value() or whatever, but this spoils the look of things a bit. Does anyone know if it is possible to do this, and if so how? Also, is there a more general solution to the whole problem, rather than having to define every operator for the class to perform operations on ints. ------------------------------------------------------------ We've run into the same problem and, to us, it is the most serious (apparent) structural limitation in providing well-packaged user-defined data types in C++. Is there a clean, general solution? -- Martin L. Smith Amoco Research Center P.O. Box 3385 zmls04@trc.amoco.com Tulsa, OK 74102 [zmls04@sc.msc.umn.edu] 918-660-4065