> C++ has nothing to do with C? I would not agree with that assertion, but I get what the writer meant.
On the one hand C++ is an almost perfect superset of C. The things that work in C but not in C++ are pretty obscure. 99 out of 100 C programs will compile and execute correctly if you compile them as C++ programs. On the other hand C++ is a whole lot more than C. C is assembler-like in that the designers were thinking about "how does a computer work? What machine instructions will be necessary for this function? Will this be easy to do?" when they designed the language. C++ is full-on OOP. They designed for an OOP paradigm and figured they could generate code to support it somehow. (You can criticize C++ or say Java is better or whatever but it is undeniably a full-court implementation of OOP.) I *love* OOP. I have written two largish commercial product families in C++. You have the almost-assembler-level flexibility of C, but then the OOP constructs force a discipline and a way of thinking on you that I find very helpful. (Others might find it restricting or confusing.) Here's an example. One of the fundamental concepts of OOP is encapsulation, which (my unofficial definition) is a bundling of "record layout" and executable function. Suppose you were writing a product library in assembler. You might tell your co-workers "this DSECT represents one Widget. If you want to deal with a Widget you should GETMAIN a Widget DSECT." Oh, by the way, the length of the DSECT is in Widget_Len so GETMAIN that much storage. Oh, and you need to call WIDGINIT first thing to initialize your Widget, and before you FREEMAIN a Widget you should call CLOSWIDG. In OOP you would lay out the Widget "record" (class) and bundle in it a "constructor" and a "destructor" routine. The compiler would automatically generate code to call those routines every time someone allocated or deallocated a Widget. So you would not have to tell people to call those routines themselves, nor deal with people who said "your Widget does not work" and let you debug for an hour before you figured out they had not called WIDGINIT. The length is also bundled in magically, so properly allocating and initializing a Widget could come down to one line of code: Widget mywidget; I like that. Others might find it constricting. There is much, much more to OOP; that is just one easy example. > the difference between a general function and the method of an object Classes have "static methods" that are generic and pretty much always available, and "instance methods" that apply to a particular instance of a class. If you had a class that represented a dog you might have a static method "what species are you?" that would always return "Canis familiaris." On the other hand a method "what is your name?" would have to be an instance method. A particular instance or example of a dog has a name; asking dogs in general "what is your name?" would be meaningless. You could always ask the dog class what its species was, but to ask for a name you would need to have a particular dog (an instance of the dog class) to ask. Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf Of Bob Bridges Sent: Wednesday, January 5, 2022 12:10 PM To: [email protected] Subject: Re: Sockets? Yeah, so maybe it wasn't a C compiler that I bought. It's been a long time; I'm not sure any longer. And I'm pretty sure that at the time I didn't comprehend what OO programming was about. The descriptions I read, and the examples, didn't seem all that different to me; what's the big deal?, I wondered. But when trying to program in VBA/Excel I kept running into the message "does not support this property or method", which drove me crazy since I'd JUST USED IT OVERE HERE! I didn't understand the difference between a general function and the method of an object, you see. It wasn't until I followed a VBA programmer's advice and tried writing my own class, even though I didn't particularly need one at the moment, that it suddenly became clear. I've been a fan ever since. C++ has nothing to do with C? That's weird. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
