When it comes to C++ everything is pushed beyond limits, and so it the case of a class defined with struct or union keyword. But the point I would like to share with you on this post is the key difference involved.
The concepts of class and data structure are so similar that both keywords (struct and class) can be used in C++ to declare classes (i.e. structs can also have function members in C++, not only data members). The only difference between both is that members of classes declared with the keyword struct have public access by default, while members of classes declared with the keyword class have private access. For all other purposes both keywords are equivalent.
In a similar fashion, the concept of unions is different from that of classes declared with struct and class, since unions only store one data member at a time, but nevertheless they are also classes and can thus also hold function members. The default access in union classes is public.
Credit : Juan Soulie
Credit : Juan Soulie
No comments:
Post a Comment