[ACCEPTED]-is there a difference between a struct in c++ and a struct in c#?-c++

Accepted answer
Score: 27

In C# you use structs to define value types 9 (as opposed to reference types declared 8 by classes).

In C++, a struct is the same thing 7 as a class with a default accessibility 6 level of public.

So the question should be: are 5 structs in C# different from classes in 4 C++ and, yes, they are: You cannot derive 3 from C# structs, you cannot have virtual 2 functions, you cannot define default constructors, you 1 don't have destructors etc.

Score: 13

Structs in C# very different from classes, see 4 Structs vs Classes for more

Structs in C++ are identical to 3 classes, EXCEPT that members are public 2 by default. Other than that, a C++ struct 1 can do everything a C++ class can do.

Score: 0

Yes.

structs in c# are plain old, by value, data 4 types (as opposed to classes that are by 3 reference and have ll the OO stuff)

structs 2 in c++ are just class that are public by 1 default.

Score: 0

Are you trying to interoperate between managed 2 C++ and C#? If so, there are extensions 1 to C++ to allow this: see link

Score: 0

A C# struct is managed code, which will 7 be freed by the C# garbage when nobody refers 6 to it anymore. Its destructor is called 5 whenever the garbage collector decides to 4 clean it up.

A C++ struct is an unmanaged 3 object, which you have to clean up yourself. It's 2 destructor is predictably called when you 1 delete it, or it goes out of scope.

More Related questions