rohit shekhar wrote: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 respect, structures and classes are equivalent." for only this difference what is the need of class we can achieve everything using struct only i think...
Well, long ago in ancient times, we C++ programmers had the coding convention of using C++ classes mostly for encapsulation and using C++ structs only for no encapsulation. So during design conversations, when we talk about structs we always knew we were discussing publicly accessible members. Classes would mean otherwise, where there would be some private members. Yes, technically C++ classes and structs were the same but the difference was in how they were used in the programming.