| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | object oriented c |
PE> Paul, I noticed that you used a similar but different method
PE> of doing object-oriented C. How about telling us what the
PE> advantages are of your style? Maybe it's me that should
PE> be changing, but I'd like to know why. BFN. Paul.
Paul,
Apart from a few minor differences such as function names, there's only one
real difference. In your header files you declare your class as a structure
and I declare mine as a pointer. The effect is that all of your data member
are public and all of mine are private. I feel that making things private
is the better approach as it discourages fiddling with the internals of the
class.
My technique has one problem though. Because I typedef the class as a
pointer to a void, and the type checking isn't strict enough to pick this
up, it means that you can pass the wrong type of variables to my routines.
The type checking in C++ is strict enough from memory, but if I was
programming in C++ then I wouldn't be using this technique anyway :-)
What I'm playing with now is a hybrid of our two styles. Basically it
consists of defining a struct for the class as you do, but including a
pointer to the private data as I currently do. The definition looks
something like this:
struct xyz
{
void *privateStuff;
}
This allows data to be kept private and for the compiler to do type checking.
What it also allows is for public data to be included as well:
struct xyz
{
void *privateStuff;
/* public stuff follows */
int x;
char y;
float z:
}
This is the best solution I've come up with so far.
Paul
--- GoldED/2 2.42.G0214+
* Origin: It's not even a nice place to visit (3:711/934.1)SEEN-BY: 690/718 711/809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.