Inheritance in C++

Posted on 1998-10-26
Last Modified: 2010-04-02
How do you declare a base class "LIST"? (what are its methods and attributes?) The subclasses,Point,Line and Rectangle inherits the methods and attributes of this super class. Think of these shapes as a list of N Point ( using putpixel function to draw a point)
Question by:Gideon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1

Author Comment

ID: 1176253
Edited text of question

Author Comment

ID: 1176254
Please help me urgently . I have got to submit this assignment.

Expert Comment

ID: 1176255
I think you mean 'template' so here goes:
from the VC++m on-line help:


C++ Specific ®

template < [typelist] [, [ arglist ]] > declaration

The template declaration specifies a set of parameterized classes or functions.

The template parameter list is a comma-separated list of types (in the form class identifier or typename identifier) or a non-type to be used in the template body. The declaration field must be a declaration of a function or class.

You can instantiate a class template much like you would instantiate a normal class, but include the template arguments within angle brackets. No special syntax is required to call a function template.

See Also   Template Topics

END C++ Specific


// Example of the template keyword
template <class T, int i> class TestClass {
   char buffer[i];
   T testFunc(T* p1 );

template <class T, int i>
T TestClass<T,i>::testFunc(T* p1) {
    return *(p1++)

// To create an instance of TestClass
TestClass<char, 5> ClassInst;

Hope this helps,
Good luck in your assignment,
Arnon David.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 22

Expert Comment

ID: 1176256
Did that help?
LVL 10

Expert Comment

ID: 1176257
class LIST {
  POINT* m_pPoints;
  int m_nPoints;
    : m_pPoints(NULL)
    , m_nPoints(0)
  virtual ~LIST() {
  void SetSize(int n) {
    // if n == m_nPoints return
    // delete old array with delete[]
    // allocate new array with new
    // set m_nPoints accordingly
    // NOTE: this does not let you keep points when
    // changing the size
  void SetAt(int i, POINT p) {
    m_pPoints[i] = p;
  void Draw() const {
    for (int i = 0; i < m_nPoint; i++) {
      putpixel (m_pPoints[i]); // depends on impl of putpixel

class Rect : public LIST {
  void Set (int x1, int y1, int x2, int y2) {
    POINT p0 (x1,y1);
    POINT p1 (x1,y2);
    POINT p2 (x2,y2);
    POINT p3 (x2,y1);


Expert Comment

ID: 1176258
RONSLOW, I thought that we at EE weren't suposed to help pupils with their school homework. (I'm sure you know this)
LVL 22

Expert Comment

ID: 1176259
we are supposed to HELP them, we aren't supposed to DO their work.  This seems a bit borderline to me.  He gave a very complete example, but only of part of the project.  The student has to apply that to the rest.  Personally, I wouldn't have done as much, but I think its just a judgement call.

Author Comment

ID: 1176260
Arnord is completely off target,may be he did not understand the question.This is my first time to use expert-exchange facility and i did not expect such disfunctional behavior from Arnord.I did not ask him to do the assignment for me, i merely asked for help so that i can DO my own work.Nietod,thanks for the comment and Ronslow thanks for your HELP.How do i transfer the point to you??Arnord,you started at this level as well,next time it will be your brother.Do you expect me to respond the same way??
LVL 22

Expert Comment

ID: 1176261
>>Arnord is completely off target,may be he did not understand the question
I think he was trying to pinpoint the area that was giving you the difficulty so he wouldn't provide too much help.  Apparently he missed.  But if that happens in the future, you an always add a comment explaining the situation and/or asking the export for more help.  That is why I added that "Did that help?" comment.  

>>.How do i transfer the point to you
RONSLOW will have to submit a "dummy" answer.  Then you can grade it.  He is in Australlia so he's probably sleeping now.
LVL 10

Accepted Solution

RONSLOW earned 80 total points
ID: 1176262
I'm awake now !!

Arnond ... I didn't think my answer was anywhere near 'complete' enough to be considered doing his homework for him.  I just gave him a starting point (only the easy stuff).  The main work is in the bits I've left out (and in debugging and understanding what I _did_ put up there).

Like all ethical experts here (such as yourself), I will _not_ do someone's assignment for them .. but a nudge (or push) in (hopefully) the right direction is generally accepted as OK.  There are _some_ experts who don't agree with this and will quite happily help someone cheat.


PS: Gideon .. I am _not_ suggesting that you are cheating (or attempting to), but there _are_ many students who simply post their assignment questions verbatim and expect us experts to answer them ... these sort of questions usually stand out like a sore thumb and usually get appropriate responses ... much less helpful than Arnond's :-)


Author Comment

ID: 1176263
Adjusted points to 85

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question