Mar 28.managed + native + const_1

Mar 28.managed + native + const_1 - Topics for Today Native...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Topics for Today • Native classes (i.e. unmanaged classes) that have managed data members • Reminder of differences in overloading assignment (syntax) for ref classes and native classes • Static class members • Const data members and methods
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Answer to a Question value classes and ref classes – in C++/CLI – Variables of value class types contain their own values – Variables to access reference class types have to be handles – In general, value classes and ref classes cannot contain fields that are native C++ arrays or native C++ class types value classes – – You must not include a copy constructor in a value class definition – You cannot override the assignment operator in a value class ref classes – Are comparable to native C++ classes – Do not have the restrictions that value classes have (above) – Unlike a native C++ class, a ref class does not have a default copy constructor or a default assignment operator
Background image of page 2
Mixing Managed and Unmanaged With unmanaged classes: –u s e new and delete to explicitly allocate and recover space operator syntax used to overload operators like = Complex operator+ (Complex &other); Complex & Complex::operator = (Complex &n); – if there are any managed types as data members for the class, you have to use gcroot and include the header vcclr.h (next slide) if you are using the CLI – although you do need to include static class variables in the class definition, any static class variables have to also be declared outside the class definition With managed classes – indicate that they are managed by using ref or value in the class definition –u s e
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mixing Managed and Unmanaged (ii) You cannot declare a handle type in a native type. – If you try something like this: class CppClass1 { public: String^ str; CppClass1() {} }; – The compiler will generate an error: error C3265: cannot declare a managed 'str' in an unmanaged 'CppClass1 may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap So how can you use a managed thing (such as a String) as a data member of a native class or type? vcclr.h
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/30/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 18

Mar 28.managed + native + const_1 - Topics for Today Native...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online