From 4486641799976847789
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,5e585716c0fba88e
X-Google-Attributes: gidf78e5,public
From: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Subject: Re: why are private functions part of a class' interface?
Date: 1995/04/18
Message-ID: <3n0sh6$7q1@hpsystem1.informatik.tu-muenchen.de>#1/1
X-Deja-AN: 101111609
distribution: world
references: <VLADIMIR.95Apr12160158@tees.cs.ualberta.ca> <3mjfjr$c98@etca.etca.fr>
organization: Technische Universitaet Muenchen, Germany
newsgroups: comp.std.c++


In article <3mjfjr$c98@etca.etca.fr>, chris@alofi.etca.fr (Christian Millour) writes:
[..]
|> Provided that you don't need your private helper functions
|> in friend classes, you might consider implementing them as
|> (static) members of an opaque friend, e.g.: 
|> 
|> Foo.h: --------------------
|> 
|> class Foo {
|> public:
|>   Foo();
|>   double avg() const;
|> private:
|>   double a, b, c;
|> friend struct FooHelpers;
|> };
|> 

BTW, can a namespace (that is not a class) be the friend of a class?

|> Foo.cc: -------------------
|> 
|> #include "Foo.h"
|> struct FooHelpers {
|>   static void primify(Foo& aFoo) {aFoo.a = 2; aFoo.b = 3; aFoo.c = 5;}
|>   static double sum(const Foo& aFoo) {return aFoo.a + aFoo.b + aFoo.c; }
|> };

To let FooHelpers provide _private_ helper functions it should be:

struct FooHelpers {
  friend class	Foo;
private:
  static void primify(Foo& aFoo) {aFoo.a = 2; aFoo.b = 3; aFoo.c = 5;}
  static double sum(const Foo& aFoo) {return aFoo.a + aFoo.b + aFoo.c; }
};

A IMHO more straight foreward way would be:

namespace Foo {
	void primify(Foo& aFoo) {aFoo.a = 2; aFoo.b = 3; aFoo.c = 5;}
};
Foo::Foo() {
	primify(*this);
};

Giving the currently prohibited members-added-to-a-namespace-that-is-a-class
a usefull meaning.


Ulf Schuenemann

--------------------------------------------------------------------
Ulf Sch�nemann
Fakult�t f�r Informatik, Technische Universit�t M�nchen, Germany.
email: schuenem@informatik.tu-muenchen.de



