Inheriting methods between classes

I have 2 classes that inherit from a liked list type structure I have written. The 2 classes work mostly the same except for 1 method so I want to inherit the methods from one class into the other instead of re writing them. Here is some of the the code I have however it doesn't work. I have a basicList and complexList.

basicList.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "List.hpp"
#include "LinkedList.hpp"

class basicList : public list {
public:

    basicList();
    LinkedList list;
 
    virtual ~basicList();

    virtual unsigned int count() const;
};


basicList.cpp
1
2
3
4
5
6
7
8
9
10
#include "basicList.hpp"

  basicList::basicList(){
	   LinkedList list;
}

   unsigned int basicList::count() const{
	   return list.listSize();
   }
}


complexList.hpp
1
2
3
4
5
6
7
8
9
10
11
#include "basicList.hpp"

class complexList : public basicList {
public:
    complexList();
    linkedList list;

    virtual ~complexList();

    virtual unsigned int count() const;
};


complexList.cpp
1
2
3
4
5
6
7
8
9
#include complexList.hpp;

complexList::complexList(){
    linkedList list;
}

unsigned int complexList::count() const{
	return basicList::count();
}

if u want the same function which is returning the same as basiclist"count()" ,then in complexList no need to it write again for example

:
class A
{
public :
count ();
}

class B :public A
{
}
main()
{
A a;
a.count();
B b;
b.count(); //will call the A.count()
}



}
Topic archived. No new replies allowed.