Click to See Complete Forum and Search --> : C and C++


LindisfarneBabe
02-06-2001, 07:12 PM
I’ve just started taking a C programming class at college. The same time I started the C class, my friend started a C++ class. With the exception of things like “iostream” and the strange words C++ people use for printf and scanf, I can’t see that much difference!

Can anyone tell me, what it is that makes C++ object orientated and C just regular very powerful language that you can do anything with? Also, what is object orientated programming anyway?

Any comments and help on the above will be most gratefully received,

Lindi
:confused:

Strike
02-06-2001, 07:21 PM
Well, classes, really. C doesn't have them, C++ does. And C++ uses OOP principles (well, it is supposed to, though it can work like C because of backwards compatibility). It's hard to explain if you haven't done object-oriented programming before.

:david:
02-06-2001, 07:22 PM
when you get to structures you'll see the very beginnings of OOP (object oriented programming). OOP is a very powerful and useful (programming) paradigm. It makes certain tasks much easier. C is a powerful, robust enough language to allow you to do anything, provided you have enough skill.
If you've never done any programming, it'll take some time to explain OOP.

Stuka
02-07-2001, 12:43 AM
What they are trying to say, basically, is that the C++ language has certain features available that make it much simpler to do object-oriented programming. While such programming can be done in C (i.e. GTK+), it is much more difficult and ungainly. Keywords like class, public, private, protected, friend, etc. (and the proper use thereof) make it far easier to code OO programs and actually shape the design of the program into a truly object-oriented pattern.

LindisfarneBabe
02-07-2001, 01:39 PM
Thanks to David and to Stuka for taking the time out to reply to my post. I can see now that I’ll have to wait till I get onto structures before I’ll start seeing how OOP comes into it’s own.

Once again, thanks for the replies guys,

Lindi
:)

vhg119
02-07-2001, 07:46 PM
i never truly understood the difference between structs and classes.
anyone care to explain?

Strike
02-07-2001, 08:26 PM
Originally posted by vhg119:
i never truly understood the difference between structs and classes.
anyone care to explain?

Classes provide data-hiding, structs don't. You can declare private members of classes, so that no one can use them except the class itself. That's the biggest difference I can think of.

Energon
02-08-2001, 12:54 AM
Originally posted by Strike:
Classes provide data-hiding, structs don't. You can declare private members of classes, so that no one can use them except the class itself. That's the biggest difference I can think of.

function encapsulation stands out to me, personally, much more than data-hiding...

Strike
02-08-2001, 02:25 AM
Originally posted by Energon:
function encapsulation stands out to me, personally, much more than data-hiding...
You can encapsulate functions within structs, I thought...

jemfinch
02-08-2001, 07:59 AM
Originally posted by Strike:
You can encapsulate functions within structs, I thought...

In C++ you can. In C, the closest you'll get is putting function pointers in structs, and they'll still be only "functions" and not "methods" because they have no method of knowing which object they were called from.

Jeremy

Ben Briggs
02-08-2001, 12:54 PM
This is no big deal, but those "strange words people use for printf and scanf" (cout and cin) are short for C Output and C Input.

Like I said, it's no big deal, I just wanted to clarify for you.

pwrhouse
02-08-2001, 07:04 PM
Actually its console output and console input

Strike
02-08-2001, 08:43 PM
Originally posted by pwrhouse:
Actually its console output and console input
Actually, I don't think it's formally defined anywhere. cin is STDIN, cout is STDOUT, and cerr is STDERR. So, it would make more sense that it would be C Output/Input/Error, since none of those have to be console-related at all.

pinoy
02-09-2001, 12:53 AM
In C++ structs *are* classes with default protection of public:

ie.

struct X {
int i;

X() : i(0) {}
};

is the same as
class X {
public:
int i;

X(); i(0) {}
};

C of course is different. This is why you don't have to typedef a struct so you can use it without the struct keyword.