🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #830

No friendship for private constructors?

#830
From: Perry The Cynic
Date: Sat, 16 Feb 1991 07:13
37 lines
1735 bytes
Consider the following program:

	class One {
		friend class Two;
	private:
		One();
	};

	class Two {
		static One test;
	}

	One Two::test;

The last line draws an error from both cfront and Turbo C++:
	error:  ..() cannot access One::One(): private  member

Why the complaint? My interpretation of the scoping rules says that
the Two:: qualifier puts me into Two's scope. Since Two is a friend
of One, I don't see why it can't access One's private constructor.
Incidentally, the error remains even if I rewrite the last line as
	One Two::test = One();
and the ARM says explicitly that the initializing expression is
interpreted in the context of Two.

What am I misunderstanding here? Can somebody quote the language rule
that I'm missing? Or are both compilers violating the language standard?
Oh, and how do I write this legally? The intent is to make it impossible
to create objects of type One, except inside Two (which then hands out
references to One objects).

Thanks
  -- perry
-- 
--------------------------------------------------------------------------
Perry The Cynic (Peter Kiehtreiber)		       perry@arkon.key.com
** What good signature isn't taken yet? **  {amdahl,sgi,pacbell}!key!perry
Technical Details
Message-ID: <2442@key.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!amdahl!key!perry

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!amdahl!key!perry
From: perry@key.COM (Perry The Cynic)
Newsgroups: comp.std.c++,comp.lang.c++
Subject: No friendship for private constructors?
Summary: Is this really illegal?
Keywords: C++ friend private constructor
Message-ID: <2442@key.COM>
Date: 16 Feb 91 07:13:58 GMT
Reply-To: perry@arkon.key.COM (Perry The Cynic)
Organization: Key Computer Laboratories, Fremont
Lines: 37