Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


263. Can a constructor be declared a friend?

Section:11.4.5  [class.ctor]    Status:CD1    Submitter:Martin Sebor    Date:13 Nov 2000

[Voted into WP at April 2003 meeting.]

According to 11.4.5 [class.ctor] paragraph 1, adeclaration of a constructor has a special limited syntax, inwhich onlyfunction-specifiers are allowed. Afriendspecifier is not afunction-specifier, so one interpretationis that a constructor cannot be declared in afrienddeclaration.

(It should also be noted, however, that neitherfriendnorfunction-specifier is part of thedeclaratorsyntax, so it's not clear that anything conclusive can be derivedfrom the wording of 11.4.5 [class.ctor].)

Notes from 04/01 meeting:

The consensus of the core language working group was that itshould be permitted to declare constructors asfriends.

Proposed Resolution (revised October 2002):

Change paragraph 1a in 6.5.5.2 [class.qual] (added bythe resolution of issue 147) as follows:

If thenested-name-specifier nominates a classC, and thename specified after thenested-name-specifier, when looked up inC, is the injected-class-name ofC (Clause 11 [class]), the name is instead considered to name theconstructor of classC. Such a constructor name shall be usedonly in thedeclarator-id of aconstructor definitiondeclaration thatappears outside of the class definitionnames a constructor....

Note: the above does not allow qualified names to be used forin-class declarations; see 9.3.4 [dcl.meaning] paragraph 1.Also note thatissue 318 updates thesame paragraph.

Change the example in 11.8.4 [class.friend], paragraph 4as follows:

class Y {  friend char* X::foo(int);friend X::X(char);   // constructors can be friendsfriend X::~X();      // destructors can be friends  //...};



[8]ページ先頭

©2009-2026 Movatter.jp