Topic: Where next for C++: static, local methods
Author: Horst von Brand <vonbrand@inf.utfsm.cl>
Date: 1997/11/04 Raw View
Eric Bloodworth <eric@rrinc.com> writes:
> It always seems silly to me to have to define a
> method which is used only in one source file and then
> have to go back to the class definition and declare it
> "private" there too. Why not relax the rules a little
> and allow static, non-virtual methods be declared outside
> of the public class definition?
you would be giving users of your class a loophole through which they can
do _anything_ to the innards of your class without your permission.
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Eric Bloodworth <eric@rrinc.com>
Date: 1997/10/31 Raw View
It always seems silly to me to have to define a
method which is used only in one source file and then
have to go back to the class definition and declare it
"private" there too. Why not relax the rules a little
and allow static, non-virtual methods be declared outside
of the public class definition? In other words, since
such methods can't be linked to by any other compilation
unit, and they aren't needed to build a vtable, there's
no reason to require that they be declared in the class
declaration. I should then be able to declare or define such
a method at the top of the source file that it is used.
-- Eric
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/10/31 Raw View
Eric Bloodworth <eric@rrinc.com> writes:
>It always seems silly to me to have to define a
>method which is used only in one source file and then
>have to go back to the class definition and declare it
>"private" there too.
The problem is that C++ doesn't have a module system.
Instead, classes are the unit of protection, and so
if you want to have access to private members, you need
to modify the class declaration.
>Why not relax the rules a little
>and allow static, non-virtual methods be declared outside
>of the public class definition?
Because this would significantly weaken the protection offered
by "private": anyone who wants to modify a private member
need only define a new static non-virtual method for the
class.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/11/01 Raw View
Fergus Henderson wrote:
>
> Eric Bloodworth <eric@rrinc.com> writes:
>
> >It always seems silly to me to have to define a
> >method which is used only in one source file and then
> >have to go back to the class definition and declare it
> >"private" there too.
>
> The problem is that C++ doesn't have a module system.
> Instead, classes are the unit of protection, and so
> if you want to have access to private members, you need
> to modify the class declaration.
>
> >Why not relax the rules a little
> >and allow static, non-virtual methods be declared outside
> >of the public class definition?
>
> Because this would significantly weaken the protection offered
> by "private": anyone who wants to modify a private member
> need only define a new static non-virtual method for the
> class.
One may argue that providing a specialisation for a member
template lead to the same results.
And someone proposed here a way to have incomplete class
definitions. Without going that far, we could have a
private class definition:
class Foo {
public:
protected:
// all members
private:
// only virtual functions and data members
private ... // means to be continued
};
class private Foo {
// private functions
};
Of course for full data hiding and to avoid recompilations,
one must use the opaque type pattern (see my patterns page:
http://www.pratique.fr/~bonnardv/patterns_e.html#handle.body).
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]