1

While working through a DX11 tutorial I came across this bit of code:

typedef struct
{
  float x, y, z;
}VertexType;

How is this different from:

struct VertexType
{
  float x, y, z;
};

I have read some other questions on typedef and it does not seem to be normally used as it is here. Can anyone explain if there is difference?

Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70
Alexander Van Atta
  • 870
  • 11
  • 34
  • 3
    The first is a C-ism, the second is more idiomatic C++. – juanchopanza Feb 26 '14 at 21:25
  • 1
    Ok thank you. I just found this answer too. http://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c/612350#612350 It seems I had to search the term "typedef struct" not just "typedef" – Alexander Van Atta Feb 26 '14 at 21:26

1 Answers1

3

The first one was born with C and is basically just legacy in C++, the second one is the C++ way of declaring a struct. There's no practical difference between the two, except that the latter would not compile in C.

Shoe
  • 74,840
  • 36
  • 166
  • 272