By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,236 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,236 IT Pros & Developers. It's quick & easy.

problems with inheritance???

P: n/a
Hi..

I have a standard windows app in C#. The project contains a two forms and one class that i have created. I want both of the forms to inherit from the class but i am getting an error reading "type in interface list is not an interface"??? i am not sure how to fix the problem. Is an interface (form) unable to inherit from a non interface type??

any help appreciated
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Darryn,
this is a little confusing because a "form" is not an interface, it is a class.
Perhaps with some code example we can get a better insight into what your goal really is.
You can't get the properties of a Windows Form class by having a class derive from another class that doesn't inherit itself from System.Windows.Forms.Form.
--Peter
"Darryn Ross" <da****@datawave.com.au> wrote in message news:Ow**************@TK2MSFTNGP11.phx.gbl...
Hi..

I have a standard windows app in C#. The project contains a two forms and one class that i have created. I want both of the forms to inherit from the class but i am getting an error reading "type in interface list is not an interface"??? i am not sure how to fix the problem. Is an interface (form) unable to inherit from a non interface type??

any help appreciated
Nov 15 '05 #2

P: n/a
"Darryn Ross" <da****@datawave.com.au> wrote in message news:Ow**************@TK2MSFTNGP11.phx.gbl...
The project contains a two forms and one class that i have created.
I want both of the forms to inherit from the class but i am getting an error


Form is a class, not an interface. Therefore, the form (which inherits
from System.Windows.Forms.Form) has already used up its one
permitted inheritance, and cannot simultaneously inherit from the
other class you have created.

C# only supports single inheritance, not multiple inheritance like C++.

The workaround is to aggregate this other class, such that your form
still inherits from form, but your form subclass must:

1. Contain an instance of the other class you've created in the
constructor as a member field.

2. Expose the methods and properties of the class you've created.

Aggregating the class, I'll call it T, in lieu of inheriting from it, would
look something like this:

public class F : Form
{
private T impl;
public F( ) { impl = new T( ); }
public int Foo( int x) { return impl.Foo( x); }
}

Normally, its desirable to make the methods and properties of the
aggregated class to be defined in an interface. Then anyplace where
you might ordinarily expect an instance of this class, you would use a
reference to this interface instead. The form class, instead of inheriting
from two classes, could inherit from one class and implement the interface
of the aggregated object (which supplies the actual implementation of
the interface and is delegated to by the form).

In a more interface or type-driven manner such as this, not having multiple
inheritance is not a problem.
Derek Harmon
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.