Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucsd!pacbell.com!lll-winken!bert.llnl.gov!howell From: howell@bert.llnl.gov (Louis Howell) Newsgroups: comp.std.c++ Subject: Re: Declarations of Member Functions Outside Class Definitions Message-ID: <65800@lll-winken.LLNL.GOV> Date: 3 Aug 90 00:37:13 GMT References: <46393@brunix.UUCP> <65729@lll-winken.LLNL.GOV> <1946@ux.acs.umn.edu> Sender: usenet@lll-winken.LLNL.GOV Reply-To: howell@bert.llnl.gov (Louis Howell) Organization: Lawrence Livermore National Laboratory Lines: 56 In article <1946@ux.acs.umn.edu>, hopper@ux.acs.umn.edu (hopper) writes: |>In article <65729@lll-winken.LLNL.GOV> howell@bert.llnl.gov (Louis Howell) writes: |>>In article <46393@brunix.UUCP>, sdm@cs.brown.edu (Scott Meyers) writes: |>>|>Proposed: |>>|> |>>|> That it be possible to declare member functions outside of class |>>|> declarations exclusively for the purpose of later friend declarations. |>>|> |>>|>Example: |>>|> |>>|> class Example; // currently legal |>>|> void Example::f(int); // currently illegal, but would be ok |>>|> |>>|> class Sample { |>>|> friend void Example::f(int); // currently legal, provided class |>>|> // Example has been defined |>>|> |>>|> }; |>> |>>Why should even this be necessary? The friend declaration contains all |>>of the information necessary to deduce the declarations of Example and |>>Example::f(int), so why not omit these declarations too? |> |>Stuff deleted. |> |> I'm not precisely certain of how this is implemented, but what if |>you declared a virtual member function of a class, and then use the |>mechanism proposed in this article to declare it to be a friend? If you |>called this function, how would the compiler generate the code to select the |>proper virtual function if it was unaware of the other parts of the class |>declaration? More stuff deleted. I'm not sure that I understand what your objection has to do with the idea of friends. I'm not proposing any change to the virtual function mechanism or the required order of declarations. As I understand it, at least, all a friend declaration accomplishes is an override to the privacy rules. I want to be able to tell the compiler to remember an exception of the following form: "The private data (and functions) of this class should be accessible to a function called f(int) in a class called Example." It shouldn't matter if the compiler has ever heard of Example or Example::f(int), all it has to do is remember that a function with that name should have access to private parts of class Sample. If the function is virtual, then a separate friend declaration would be required for the functions Derived_from_Example::f(int), Also_Derived_from_Example::f(int), and so on, if they are also to have special access. Am I missing something here, or are we talking about two different things? Louis Howell #include