Whats the difference between structures and classes (other than the privacy factor for the member variables of classes) when we can do same things in both ?
There is no difference, other than default privacy. In C days, structs just held variables and no methods. I don't know of anyone who uses structs as classes, even now. They just still get used as C structs. I believe they made it in C++ for capability with C.
If we can declare functions in both; whats the point of classes then ?
Because in OOP you use classes to define object templates. Not structs. It's what people are used to seeing, and what they want to see. C++ was designed to be fully compatible with C, so the struct had to say. POD structs in C++ are supposed to be compatible with C structs, but you can use structs in C++ just like classes if you so desire.
@darkestfright,
You actually don't save any typing. In your class, you can define your private variables above your public modifier, and then you don't have to type private. Doing that, you actually save two key strokes if you use classes :D
In C++ structs and classes are exactly the same thing (aside from the default storage modifier, as already mentioned before). struct is there to support legacy C code (and most people will use struct to indicate they want POD), class is there because 'class' is the word thats most commonly used to describe the concept.
You actually don't save any typing. In your class, you can define your private variables above your public modifier, and then you don't have to type private. Doing that, you actually save two key strokes if you use classes :D
But I don't put the private members at the top, I put the public stuff at the top because that's what I want people to see first. I jam all the private stuff at the bottom because people shouldn't be looking at it.
But I don't put the private members at the top, I put the public stuff at the top because that's what I want people to see first. I jam all the private stuff at the bottom because people shouldn't be looking at it.
But if your class definition is reasonably sized, top or bottom shouldn't really matter anyway. I don't know, I tend to stick private up top and public on bottom.