+ 7
What are the differences between a class and a structure?
I know that a structure has only variables and not methods. But a class can have variables and methods. This is the greatest difference between a structure and a class. I am looking forward for other differences.
4 Answers
+ 3
in c++ a struct is simply a class with members public by default and you can define constructors and other members functions for it
+ 6
The members and base classes of a struct are public by default, while in class, they default to private. Note: you should make your base classes explicitly public, private, or protected, rather than relying on the defaults.
Struct and class are otherwise functionally equivalent.
+ 5
thanks
+ 3
The members and base classes of a struct are public by default, while in class, they default to private. Struct and class are otherwise functionally equivalent.
They are however used in different places due to semantics. a struct is more like a data structure that is used to represent data. class, on the other hand, is more of a functionality inclined construct. It mimics the way things are and work.
In c there is no option for declaring member function in structure. But c++ have ... Thanks to encapsulation and Access specifier