Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Multiple Inheritence.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 DarkScience   Members   -  Reputation: 36

Like
0Likes
Like

Posted 20 May 2012 - 01:40 AM

What I am trying to accomplish is a form of inheriting multiple classes, I tried interfaces but they are rather limited, then i tried abstract classes. Everything seemed fine but as it turns out (as i forgot) a class can only have 1 base class.
Is there a way to have a bunch of base classes and have them inherit/ be inherited ?
Below is 2 of the class files im trying to inherit.

  • interface - FAILED, cant enable external acces (public) for members, cant use virtual, cant specify default values
  • class (abstract) - FAILED
  • layer inheriting this inherits this which inherits that, i know this is a bad idea and wouldnt work. - NOT A GOOD IDEA , FUNDAMENTALLY FLAWWED

Spoiler

Spoiler


Also found this, currently trying to make sense of it.
http://msdn.microsof...y/64hstbtx.aspx

Sponsor:

#2 Knorben   Members   -  Reputation: 104

Like
0Likes
Like

Posted 20 May 2012 - 02:02 AM

In C# you use interfaces instead of inheriting from multiple base classes. What is it that you're trying to do? If you wind up with multiple inheritance in your design, you should try to rethink your design more often than not.
The link you found is for C++, in which multiple inheritance is allowed. It's not allowed in C#.

Edited by Knorben, 20 May 2012 - 02:03 AM.


#3 DarkScience   Members   -  Reputation: 36

Like
0Likes
Like

Posted 20 May 2012 - 02:07 AM

My end goal is being able to inherit varius members from varius files without haveing to retype. Along with being able to use casting to invoke/access. where interfaces fail is the inability to specify values such as "public bool ShouldDoStuff = false;" or even specifying the members to be public/private. I will probably adjust my design model to something that uses interfaces. I'm just wondering if i can still assign values, use virtual, ect ...

Thought it appears not so nuts to me, Time to get complicated or sloppy.

#4 Knorben   Members   -  Reputation: 104

Like
0Likes
Like

Posted 20 May 2012 - 02:19 AM

An interface only defines the behavior of a class, not the state. In other words, an interface doesn't (can't) have variables, only methods. It's basically a class consisting of only abstract methods, with the distinction that you can implement several interfaces, where you can only extend one class.

#5 DarkScience   Members   -  Reputation: 36

Like
0Likes
Like

Posted 20 May 2012 - 02:24 AM

Well this sucks, oh well. Guess i'll specify these things on a per class basis.
Though 1 more thing.

If i have a class with.
public String SomeVariable = "";
and i cast another class that has that property defined to this one.
will i be able to access its value ? (acces classA's version of the value ?)

ClassA : ClassB

#6 Knorben   Members   -  Reputation: 104

Like
0Likes
Like

Posted 20 May 2012 - 02:27 AM

If Bar extends Foo, and you have a variable a of type Bar, you can cast it into a Foo type. You need the inheritance, not just the same fields.
My advice is to rethink your design, it sounds as if you could maybe fashion something less complicated.

#7 DarkScience   Members   -  Reputation: 36

Like
0Likes
Like

Posted 20 May 2012 - 02:32 AM

Alright thanks for your help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS