What is the difference between c++ structs and c# structs..?
-
I have only a small idea about .net and what I understand is.. In both c++ and c#, strctures and class are used for grouping memeber variables. How ever when you create a object of strcture in c#, it is created in stack and when you create a class object, it is created in heap. In c++, the structre or class dosent have much dIfference. But if you create it uisng the new, it is created in heap and simply declaring it creates the objects in the stack. Please correct me if am wrong....
-
Structs are used in both languages to encapsulate related variables. Structs differ between C++ and C# in how they compare with classes. In C#, a struct is a value type, while a class is a reference type. In the managed world, there are value types, which can be and most often are stored on the stack (or as a member of a class) and reference types which are always allocated on a heap. In C#, a struct is a value type, while a class is a reference type. This is an important concept in C# - for example, when you pass a struct as a function parameter, it is passed by value, so if the function changes the struct, the original passed object is untouched. When a class object is passed it is by reference, so any changes made by the function change the original object. That difference is why C# doesn't need *, &, and -> operators all over the place. In the native C++ world, structs and classes are the same except for default member access. Both can be allocated on the stack or the heap. Reference and value are controlled by operators, like *, &, ., and -> Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
And what is the difference between a
C# class
and aC++
one? And what about thenew
keyword? Hey, is there also any difference on the inheritance paradigm? ... :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
And what is the difference between a
C# class
and aC++
one? And what about thenew
keyword? Hey, is there also any difference on the inheritance paradigm? ... :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Getting soft... I was expecting:
CPallini shoulda wrote:
About 3 characters.
-
Getting soft... I was expecting:
CPallini shoulda wrote:
About 3 characters.
:-D :laugh: :-D You're great. Anyway, that's right: I feel a bit weak this morning. :) BTW welcome in the
THHB
. (Official investiture on my blog [^].)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]