VC++ 2005 Beta2, Mixed types not supported
I just switched from Beta1 to Beta2 and try to recompile the code I have written with Beta1.
In a managed class I get a new error:
error C4368: cannot define 'PrevMinX' as a member of managed 'MyNamespace::MyPlot': mixed types are not supportedThe error was given for the following class member:
double PrevMinX[5];Why do I get this error now?
--
Helge
[438 byte] By [
Helgeo] at [2007-12-16]
The error is in fact a warning. We chose to expose it as an error in Beta2 in order to highlight that mixed types (embedding native types into a managed class) are not supported. The only kind of native type you can embed are simple values (i.e. "double i"). However, you are still free to disable the warning through
#pragma warning(disable:4368)
Thanks,
--
Boris Jabes, Visual C++ Team
This post is provided "AS IS" with no warranties, and confers no rights
Hi,
Definitley, you cannot have a native array of doubles as a member of a managed type. It's because native arrays are allocated on the native stack whereas managed objects are on the managed heap, hence creating a problem. Remember that managed types are non-determiniscally being move by the GC(Garbage collector).
But you could just make a native pointer (that points to your array) to be a member of your managed class... eg...
ref class myClass {
public:
double* _myPtr;
myClass(){
_myPtr = new double[20];
};
~myClass() {
delete _myPtr;
};
}int main() {
myClass^ temp = gcnew myClass();
temp->_myPtr[0] = 100.0;
// don't forget to delete the managed object to be able to delete the resources..
delete temp;
}
Hope this gets you started...
BTW, heres a link that jochen gave me that discusses the Finalization, Dispose pattern...
http://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=88e62cdf-5919-4ac7-bc33-20c06ae539ae
cheers,
Paul June A. Domag