public class MainWindow : Gtk.Window
{
public MainWindow( )
{
...
}
private void OnDelete( object o, Gtk.DeleteEventArgs e )
{
...
}
}
So I'm assuming making a constructor automatically calls the parent class's constructor. What can I do about this?
[Edited by - F-Kop on September 25, 2007 12:26:40 AM]
[C#] class inheritence and constructors...ew
Alrighty..I literally just switched from C to C# for GUI projects yesterday, and I have a question. I have a class called MainWindow that extends Gtk.Window. Gtk.Window has no constructor with 0 parameters. I'm trying to make a constructor with 0 parameters for MainWindow, but apparently it's trying to find Gtk.Window() which doesn't exist.
If Gtk.Window doesn't have a constructor with 0 parameters then your code shouldn't have any problems. If it does then you might run into trouble, in which case you should invoke the parent's constructor:
public class MainWindow : Gtk.Window { public MainWindow() : base() { // Herein lies the magic. :) ... } private void OnDelete(object o, Gtk.DeleteEventArgs e) { ... }}
The error code is:
CS1501: No overload method for `Gtk.Window' takes `0' arguments.
And it points to this line:
public MainWindow( )
CS1501: No overload method for `Gtk.Window' takes `0' arguments.
And it points to this line:
public MainWindow( )
building on what Benryves said, also I have never worked with GTK Framework.
public class MainWindow : Gtk.Window { public MainWindow(<insert parameters needed for Gtk.Window Constructor here>) : base(<pass the parameters needed for Gtk.Window Constructor here from your constructor>) { ... } private void OnDelete(object o, Gtk.DeleteEventArgs e) { ... }}
If you have some kind of constant value or known expression to pass to the constructor, you could do:
(Edit) from googling, it looks like the Gtk.Window takes a string, so you could say:
public MainWindow() : base(whateverYouNeed){}
(Edit) from googling, it looks like the Gtk.Window takes a string, so you could say:
public MainWindow() : base("Main Window!"){}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement