0

I had worked with DirectX 9 approximately 8 years ago and one question has been opened till now. why Microsoft use struct for their entities instead of class? what is the benefit? I know class and struct are same(except default access specifier) and always I think the class is the meaning of object-oriented programming(because every people who know every language know class as OOP), but it seems Microsoft maybe don't think so.

again I want to emphasize that I know what is the difference between class and structure(only default access specifier differ)

A picture from one definition in directx 9.0:
A picture from one definition in directx 9.0

Claudio
  • 10,614
  • 4
  • 31
  • 71
SpongeBob
  • 383
  • 3
  • 16
  • I like to think of a `struct` being *electric* and a `class` being *electronic*, i.e. a `struct` "does fewer things". My *guess* is that in early C++ (CFront), a new keyword `class` was needed to distinguish from the C-`struct`. Now of course the differences are small indeed. – Bathsheba May 15 '19 at 08:06
  • *"I don't know what is in creator of C++ mind's to have two same things?"* at the time backwards compatibility with C was desirable. Removing `struct` or changing the way it works would have broken the C code, so it was kept that way. – Blaze May 15 '19 at 08:08
  • "what is in creator of C++ mind's to have two same things?" I suppose when the language was new the tried to make new things look new. So it wasnt enough to give `struct`s more power, but they introduced `class` to make the difference more clear. – 463035818_is_not_an_ai May 15 '19 at 08:12
  • @Blaze if the want to compatible with C why they didn't keep c struct?(one complex data type without method and ...) – SpongeBob May 15 '19 at 08:12
  • @sia72abedi so you're asking why they didn't remove its capability to have methods, etc. for no good reason? – Blaze May 15 '19 at 08:14
  • [This post](http://www.fluentcpp.com/2017/06/13/the-real-difference-between-struct-class/) and its sources, which are FAQ of the ISOCpp edited directly by Stroustrup, might help you. – bracco23 May 15 '19 at 08:15
  • @Blaze I say in C we don't have method for classes and classes are one some related data together, but in C++ they grow it near class,why?? If we have class why we need really same alternative? – SpongeBob May 15 '19 at 08:36
  • Another thing to note is that this is D3DXmath, which is deprecated along with Direct3D 9. In other words, this code was written 15+ years ago so coding styles and the C++ language have evolved somewhat since then so try not to draw too much conclusion from old headers as to what's "modern best practice". That said, I still used ``struct`` instead of ``class`` for my data types in [DirectxMath](https://walbourn.github.io/introducing-directxmath/) to avoid the redundancy of having to do ``class { public:`` everywhere. – Chuck Walbourn May 16 '19 at 22:46

0 Answers0