6
I know the difference between structs
and classes is that structs
has its public members by default, and that structs
belong to C (but nothing prevents use in C++).
In practice when creating an object for classes or a structure, who is the slowest? Which one will occupy the most memory? Who has its fastest access?
However, although it has not been asked by the OP there are differences between the two, for example: structs do not have constructors, they are not considered OO so they cannot have inheritance relationships, they cannot have methods, etc.
– Zorkind
@Can’t Zorkind? Can you talk about it? And why does it compile? https://ideone.com/LwcDwD And why is it in this documentation? http://en.cppreference.com/w/cpp/language/initializer_list
– Maniero
Okay, I was wrong about the builder, for some reason I had it in my head that I couldn’t, but what about the rest? :-)
– Zorkind
Same thing, it’s all on link that I went through.
– Maniero
Ah I had C# in my head about inheritance, sorry https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/struct :-)
– Zorkind
But anyway the builders in Struct work differently from Class so I’m not totally wrong hahahaha
– Zorkind
C# allows constructors https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-structs
– Maniero
In C++ is identical.
– Maniero
i have talked regarding the inheritance in doc I passed it is clear that Struct can not inherit from other Struct in C# :-)
– Zorkind
Another source confirming everything I said, cannot have default constructor and cannot have inheritance, in C# https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/structs
– Zorkind
Structs and classes have no difference beyond the default access modifier. In some implementations, there is no difference even pro Linker.
– Mário Feroldi