home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11751 < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.9 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Distribution: world
  5. Subject: Re: Q: static members and private constructors
  6. References: <YDD5OTF@hp832.informatik.hu-berlin.de>
  7. X-Mailer: cppnews $Revision: 1.10 $
  8. Organization: Trumphurst Ltd.
  9. Lines: 50
  10. Date: Mon, 27 Jul 1992 21:31:17 +0000
  11. Message-ID: <712297877snx@trmphrst.demon.co.uk>
  12. Sender: usenet@gate.demon.co.uk
  13.  
  14.  
  15. In article <YDD5OTF@hp832.informatik.hu-berlin.de> loewis@informatik.hu-berlin.de (M.v.Loewis) writes:
  16.  
  17. > In the following program, it is not possible to create static (class)
  18. > instances of a class with only private constructors. I suppose it is
  19. > a general compiler error:
  20. > class B;
  21. > class A{
  22. > friend class B;
  23. > A(int);
  24. > int i;
  25. > };
  26. > A::A(int){}
  27. > class B{
  28. > static A m;
  29. > public:
  30. > int func();
  31. > };
  32. > int B::func()
  33. > {
  34. >  return m.i;
  35. > };
  36. > A B::m(1);
  37. > The problem is the last statement: I think it should be possible to create
  38. > the m member of B somehow, since B is a friend of A, but all compilers I 
  39. > tried complained about sth:
  40. > BC: A::A(int) is not accessible in function _STCON_()
  41. > g++: In function _GLOBAL_$I$__1Ai(): ...invalid initializer to constructor
  42. >     for type A
  43. > CC: sorry, not implemented: static member B::m of class A with constructor
  44. > ...
  45. > So, is there a way out of this problem?
  46. I seem to remeber coming across a similar problem in another compiler - I 
  47. changed the syntax to something like ...
  48. A B::m = 1;
  49. and it worked. I have no idea whether this is applicable to your 
  50. situation, but it is worth trying.
  51. ---
  52. Nikki Locke              |                        | nikki@trmphrst.demon.co.uk
  53. Trumphurst Ltd.          | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
  54. PC and Unix consultancy  | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
  55. trmphrst.demon.co.uk is NOT connected with ANY other sites at demon.co.uk.
  56. Demon.co.uk is a dial-up subscription access point to the Internet.
  57.