Thread View: comp.std.c++
1 messages
1 total messages
Started by Perry The Cynic
Sat, 16 Feb 1991 07:13
No friendship for private constructors?
Author: Perry The Cynic
Date: Sat, 16 Feb 1991 07:13
Date: Sat, 16 Feb 1991 07:13
37 lines
1735 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads