aewarnick Posted November 16, 2003 Posted November 16, 2003 How do I make an unsafe constructor?? Quote C#
Administrators PlausiblyDamp Posted November 16, 2003 Administrators Posted November 16, 2003 you mean a constructor that uses unsafe code (pointers and such like)? The following should do the trick - you will also need to modify the project properties to allow unsafe code. public class Class1 { public Class1() { unsafe { char * str; } } } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
aewarnick Posted November 16, 2003 Author Posted November 16, 2003 (edited) I got it to work but found that I cannot pass pointers to managed types, which makes sense. The reason I was trying to use pointers was that I cannot assign a class to a class. Here is the edit method: void Edit() { if(this.surface.selWB==null) return; a.graphics.WrappedBmp wb=new a.graphics.WrappedBmp(this.surface.selWB); EditForm f=new EditForm(this.surface, ref wb); if(DialogResult.Yes==f.ShowDialog()) { this.surface.selWB= wb; this.surface.Invalidate(); this.needsSaved=true; } f.Dispose(); } In EditForm f, wb is directly modified and IS actually changed, HOWEVER, when I assign this.surface.selWB= wb; selWB does NOT change. There are no errors, just nothing! But if when I initialize wb like this: a.graphics.WrappedBmp wb= this.surface.selWB; this.surface.selWB IS changed from the EditForm. And is what I don't want. I want a new instance of WrappedBitmap to be directly changed and then assign that to this.surface.selWB only if EditForm returns Yes. Why doesn't wb when it is a new instance and modified by EditForm change selWB when it is assigned to it?? ie.. the full code above. Edited November 16, 2003 by aewarnick Quote C#
aewarnick Posted November 16, 2003 Author Posted November 16, 2003 Ok, got somewhere but don't really understand why the above does not work. Here is what I had to do: I created a method in Class WrappedBmp called Assign. When I call that and send wb to it, it works. Why doesn't the above code work? Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.