What are the benifits of using a value class in C++/CLI.Can the value class contain member functions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a
value classis aValueType– that means, whenever you assign it to another variable of the same type, the whole object gets copied into the other variable, leaving you with two separate copies. Examples of this are basic numeric data types likeint,boolordouble.ValueTypesare sealed, which means you cannot derive from them.A
ref classis a reference type – if you assign it to another variable of the same type, you copy only a reference. So the two variables basically “point” to the same data.So the main difference between
value classandref classare the copying semantics. Both can contain Methods, fields properties and so on. Also, you cannot derive from avalue class.The difference between using the
classandstructkeywords in this context is the default visibility of members. It isprivateforref/value classandpublicforref/value struct.A common misconception is that value/ref specify the storage location (value=stack, ref=heap). The storage location of each object, whether ValueType or reference type, is an implementation detail noone should rely on or make assumptions about and it is entirely at the runtime’s discretion which storage location is appropriate in any given context.