Purpose of struct, typedef struct, in C++
c++, struct
Solution
The typedef version is a special case of
typedef foo bar;
which defines a new "type" bar as an alias for foo. In your case, foo happens to be a struct. In C, this was the only way to introduce new "types" (in quotes, because they are not really equivalent to int, float and co). In C++, this is not so useful, because C++ was designed to make definition of new types easier and more complete than C (at least at the beginnings of C++), and the typedef is not even necessary to refer to a previously declared struct (or class).
Problem
In C++ it is possible to create a struct: ``` struct MyStruct { ... } ``` And also possible to do the following: ``` typedef struct { ... } MyStruct; ``` And yet as far as I can tell, no discernable difference between the two. Which is preferable? Why do both ways exist if there is no difference? Is one better than the other in style or readability?