Hello everyone! Can someone give me an example of why and when I should use a data structure? I've written this just to get the hang of it but I mean classes can do all of the things structures can and even more.
The only difference between struct and class is that struct have public members and use public inheritance by default while class use private by default.
I often use the struct keyword when I have all members public and no member functions but I could just as well have used the class keyword. There is no real difference so it's just a matter of taste.
I just use struct or class depending on whether I want an implicit public: or private: at the beginning of the class definition so I can be a lazy coder.
struct, class, and union can all have public, private, and protected member variables and member functions (optionally virtual or pure virtual), public/private/protected constructors, and public/private/protected multiple inheritance.
Peter explained the public-private difference between class and struct, so I'll just add that unions have the default-public behavior too.
I use struct as a convention when I simply want an aggregate data type. If I intend for the data members to be operated on from outside then I use a struct, but if the data needs to be hidden and modified through an interface I will use a class.
I wish the operator() function could be static...just imagine, ConvertTo<int>::(std::string("100"));
Currently you have to have a static function with a name like f
That's a function, and unfortunately it does not suit my needs of treating chars as numbers instead of characters. I have to achieve this with function overloading inside a templated class.