Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!theory.TC.Cornell.EDU!lijewski From: lijewski@theory.TC.Cornell.EDU (Mike Lijewski) Subject: Re: 2 quick questions Message-ID: <1991Jun12.124618.5166@batcomputer.tn.cornell.edu> Sender: news@batcomputer.tn.cornell.edu Nntp-Posting-Host: theory.tc.cornell.edu Organization: Cornell National Supercomputer Facility References: <1991Jun12.013440.20494@Datap.ab.ca> Date: Wed, 12 Jun 1991 12:46:18 GMT In article <1991Jun12.013440.20494@Datap.ab.ca> bramwell@covert.UUCP (Bob Bramwell) writes: > >These are very short questions. Maybe the answers will be too :-) > >1. How do I explicitly initialise a private static member variable? > For example: > class fred { > static int fd; // file descriptor; 0 is legit > }; > I'd like fred::fd to start life as -1 before the first ever > constructor invocation on a fred object. Can this be done? Here's an example illustrating what you want: #include class fred { static int fd; public: void p() { cout << fd << endl; } }; int fred::fd = -1; int main() { fred x; x.p(); return 0; } >2. The following pair of statements appears to be legitimate in C, > but not in C++: > typedef char byte; > unsigned byte thing; > Obviously what I want is a synonym for char, but C++ doesn't like > me trying to make it 'unsigned' as well. Why not? This construct is not legal in ANSI C. >-- >Bob Bramwell Snail: 10th Floor, | -- Mike Lijewski (H)607/272-0238 (W)607/254-8686 Cornell National Supercomputer Facility ARPA: mjlx@eagle.cnsf.cornell.edu BITNET: mjlx@cornellf.bitnet SMAIL: 25 Renwick Heights Road, Ithaca, NY 14850