struct and class are identical in every way, except that when declaring methods and/or data members in a class, by default, they are treated as private members of the class. In a structure, by default, all methods and/or data are public.
Naturally, you can change the permission levels of methods and data members using the appropriate label of "public:", "protected:", or "private:".
Many s/w developers that program in C++ tend to use a class vs. a struct for modeling their objects. When only data members need to be encapsulated is a struct used. But that is just based on developer's preference.
Thanks for the posts. And can I ask you what will I need the private: for? Is there any specific reason?
Mostly to ensure the safety and proper use of your class. As a really simple example, say your class has a data member that can only store a value between 1 and 10. Making that member private ensures that other users of that class can't set an inappropriate value. You'd make a method to set the value public and have it reject inappropriate values.
Think of it this way. You've got this big, complicated algorithm. It's frankly ugly, and relies on all sorts of assumptions about the input data. Trying to incorporate something like that into a larger bit of code would be pretty daunting-----who knows what might break it.
But, if you can make all that functionality class-private, and throw a simple, clean, easy-to-understand interface on the class.....suddenly all the messiness is hidden from the rest of the code. It's abstracted away, and all you have to worry about is validating arguments to the interface. It makes everything a lot easier.
I think you understood OP's confusion but not what's been said here.
I do too think that when the OP asked "why structure" in place of "class",
he was actually thinking about the struct in C, and not the struct in C++
In C++, the keyword struct and class are used interchangeably,
the difference of which is what's been said by Plasmator and others.
For example, some use the keyword struct for POD type,
so it really is a matter of perference.
You could do a simple foo class using struct and compile with C++ compiler (not C compiler).
to see this for yourself.