+ 2

what is difference between structure and classes

19th Jun 2016, 5:56 PM
Dev!L
Dev!L - avatar
3 Réponses
+ 5
A struct is syntactically similar to a class and both create a class type. In the C language a struct can contain only data memebers but this limitation does not apply to C++. In C++ the struct is essentially just an alternative way to specify a class. In fact, in C++ the only difference between a class and a struct is that by default all members are public in a struct and private in a class. In all other aspects structures and classes are equivalent.
19th Jun 2016, 6:06 PM
Sardor
Sardor - avatar
+ 1
structures do allow that. First declare a class add data and functions and then change the keyword class to struct. It will still work
19th Jun 2016, 7:44 PM
Sardor
Sardor - avatar
0
classes let you declare functions in them as well as let you define who can access these functions and member variables. structures don't
19th Jun 2016, 7:42 PM
Mandar Wagh
Mandar Wagh - avatar