Teen Programmers Unite  
 

 

Return to forum top

Inheritance and Containers

Posted by eternaldisciple [send private reply] at July 17, 2001, 12:45:38 AM

I'm starting out in C++ and I just had some opinion-based-on-experience questions.

1.) What is the benefit of single inheritance over multiple
inheritance?
2.) What is the best way to avoid multiple inheritance if necessary?
3.) What are some real-world guidelines for choosing containers?
Mainly between vectors, linked lists, and deques.

Thanx for any help you can provide.

Posted by Psion [send private reply] at July 17, 2001, 08:05:21 AM

Good questions. I unleash my hordes of answers with at least aspirations of goodness.

1) I think the main benefit is simplicity. Why would you want to worry about sorting out which of several implementations of the same method are inherited when you don't have to? Single inheritance also corresponds with the popular idea of a tree structure and distinct, simple categories from math and the like.

2) There is never any need to use it, really. For one thing, you can always avoid classes altogether with non-OO languages, so of course you can live without multiple inheritance! :-D You can also take the example of Java. In it, you can inherit from one class and as many interfaces as you want. Interfaces just specify which methods must be present without giving code for them or specifying any class fields. Thus, you indicate that you are building upon another class, while still allowing for you to make your object a valid parameter to methods that require implementations of any interfaces that you need.

3) The first point to make is that a deque does not fit in the same category as the first two. It can actually be implemented with either a vector or linked list, so I'll keep it out of the discussion. :-) The main thing with vectors and lists is this: It generally takes more effort and runtime to insert and delete elements from a vector than from a linked list. However, it takes a lot more time to access an element based just on its index number in the sequence for a linked list versus a vector. Consider which of these types of operations you will perform more when choosing the appropriate data structure.

Posted by eternaldisciple [send private reply] at July 17, 2001, 10:23:18 AM

Thanks for your help Psion. I haven't really looked into Java but I'm interested from things I've heard recently. Any suggestions on resources/reference that have helped anyone?

Posted by Psion [send private reply] at July 17, 2001, 10:28:11 AM

http://java.sun.com/docs/books/tutorial/
You don't need anything else.

Posted by gian [send private reply] at July 18, 2001, 03:37:30 AM

Psion: Do you spend your days with a sign around your neck on street corners that says "Use Java, I do, and look at what a success I am!"

Posted by lordaerom [send private reply] at July 18, 2001, 07:01:22 PM

Hey hey, Java's fun!

Posted by gian [send private reply] at July 20, 2001, 01:51:08 AM

And Lordaerom brings Psion a drink every half an hour, so he doesn't get thirsty on that street corner.

Posted by lordaerom [send private reply] at July 20, 2001, 06:11:30 PM

And I wear a sign that says 'I used Java before Psion thought it was swell'!

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.