Re: extending c++ classes and enumerations
James Kanze skrev:
I have some question about a C++ syntax that can extend classes and
You've got this already, just with a slightly different syntax.
Use the keyword struct, instead of class, and use free functions
taking a pointer to the type as first parameter, rather than
member functions. You can extend to your hearts desire.
The drawbacks is that you miss all lexical benefits C++will give you.
Such as? The real benefit of class over struct isn't lexical.
The real benefit is improved encapsulation.
Hmmm. Most of the coding guidelines I'm aware of for Pascal ban
the use of WITH, because it rapidly results in unreadable code.
Other than that, I don't see any relationship of WITH with
Secondly, XML parser Expat can be a sample how difficult it is to read
such source. The first time I saw Expat source-code I thought it was
written in C++ and then preprocessed into C with some utility parser.
Thirdly, projects that uses "light C++" (not using RTTI, templates and
exceptions in the code) only use C++ for these "lexical benefits", and
I can give examples of such project.
Again, I don't know what "lexical benefits" you're talking
about. The important difference between class in C++ and struct
in C is access control, and allowing extension of a class blows
Adding support for extending classes is hopefully a toll-free change if
it is limited to static and non-virtual functions.
Adding support for extending classes breaks encapsulation.
Completely and thoroughly. It returns C++ back to the level of
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]