Questions about classes

What circumstances would a class be required in a program?
also why do we use classes instead of structures? are they interchanable and are they more useful then structures
What circumstances would a class be required in a program?


http://en.wikipedia.org/wiki/Object-oriented_programming

also why do we use classes instead of structures? are they interchanable and are they more useful then structures


The only difference between struct and class in C++ is default member visibilty. With structs members are public by default; with classes they are private.

O-O is about classes hiding data and only communicating via well defined intrfaces. So classes are better for this purpose (hide things until you deliberately make them visible).

http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29

structs (and classes, though this is not so common) can be used as C-style "plain old data", if you just want to stores values using built in types (no methods, etc.)

http://en.wikipedia.org/wiki/Plain_old_data

See these pages and the ones they link to for the info you require.

Andy
Last edited on
The only difference between struct and class in C++ is default member visibilty. With structs members are public by default; with classes they are private.

Not only it. The default access specifier in inheritance for structures is public, but for classes is private.
@Syuf - Oops! I remembered to look right and to look left, but not up and down!
Topic archived. No new replies allowed.