C++ is a super-set of C language...C language has struct ( structures ) while C++ has struct and class ( ADT's).....by default the access specifier of struct is public and class access specifier is private.... my question is why C++ has both of them ( struct and class )....and also tell me what are the main differences between struct and class?????? thanks to seniors ......
C++ is, as you state, to a large extent a super-set of C (not quite exactly, but very nearly). C has structs, so they must be compatible with C++, so we've got struct. In C++, however, structs can have additional things (methods, privacy levels, inheritance). C++ has both to maintain compatibility with C.
As you stated, the difference between a class and a struct in C++ is the default privacy level. A stuct's members are default public; a class' members are default private. This carries into inheritance as well.
This is the only difference between struct and class in C++. You can use a struct like a class, and a class like a struct.
two more things makes struct differs from class:
struct object may be declared with struct keyword: struct Object x; //C stile where Object is an struct name and x is an object
second thing is that struct may be initialized when declared: struct Object x = { "some char", 99, 'm', "etc..." };