Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Inheritance in C++

Posted on 1998-10-26
Medium Priority
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.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 240 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

610 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