home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
- Distribution: world
- Subject: Re: Q: static members and private constructors
- References: <YDD5OTF@hp832.informatik.hu-berlin.de>
- X-Mailer: cppnews $Revision: 1.10 $
- Organization: Trumphurst Ltd.
- Lines: 50
- Date: Mon, 27 Jul 1992 21:31:17 +0000
- Message-ID: <712297877snx@trmphrst.demon.co.uk>
- Sender: usenet@gate.demon.co.uk
-
-
- In article <YDD5OTF@hp832.informatik.hu-berlin.de> loewis@informatik.hu-berlin.de (M.v.Loewis) writes:
-
- >
- > In the following program, it is not possible to create static (class)
- > instances of a class with only private constructors. I suppose it is
- > a general compiler error:
- >
- > class B;
- > class A{
- > friend class B;
- > A(int);
- > int i;
- > };
- >
- > A::A(int){}
- >
- > class B{
- > static A m;
- > public:
- > int func();
- > };
- >
- > int B::func()
- > {
- > return m.i;
- > };
- >
- > A B::m(1);
- >
- > The problem is the last statement: I think it should be possible to create
- > the m member of B somehow, since B is a friend of A, but all compilers I
- > tried complained about sth:
- > BC: A::A(int) is not accessible in function _STCON_()
- > g++: In function _GLOBAL_$I$__1Ai(): ...invalid initializer to constructor
- > for type A
- > CC: sorry, not implemented: static member B::m of class A with constructor
- > ...
- > So, is there a way out of this problem?
- I seem to remeber coming across a similar problem in another compiler - I
- changed the syntax to something like ...
- A B::m = 1;
- and it worked. I have no idea whether this is applicable to your
- situation, but it is worth trying.
- ---
- Nikki Locke | | nikki@trmphrst.demon.co.uk
- Trumphurst Ltd. | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
- PC and Unix consultancy | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
- trmphrst.demon.co.uk is NOT connected with ANY other sites at demon.co.uk.
- Demon.co.uk is a dial-up subscription access point to the Internet.
-