Path: utzoo!attcan!uunet!munnari.oz.au!sirius.ucs.adelaide.edu.au!sirius!matthew From: matthew@hydra.ua.oz.au (Matthew Donaldson) Newsgroups: comp.lang.c++ Subject: Transparent int class Message-ID: Date: 15 Oct 90 09:20:53 GMT Sender: news@ucs.adelaide.edu.au Distribution: comp Organization: Computer Science, Adelaide University, Australia Lines: 41 Nntp-Posting-Host: hydra.ua.oz.au 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. -Matthew -- ------- Matthew Donaldson matthew@cs.ua.oz.au Operating Systems Group Computer Science Department University of Adelaide