template <class Type>
void linkedListType<Type>::dividedAt(Type& div, linkedListType<Type> &otherList)
{
nodeType<Type>* trailer;
nodeType<Type>* current;
if (first == NULL)
cout << "There's nothing in this list.\n";
elseif (first->link == NULL)
current->link = NULL;
else
{
current = first;
if (current->info != div)
{ trailer = current;
current = current->link;}
elseif (current->info == div)
trailer->link = NULL;
current->info = otherList.first;
}
}
Now to show the derived class:
1 2 3 4 5 6
#include "linkedlistthings.h"
usingnamespace std;
template <class Type>
class unorderedLinkedList: public linkedListType<Type>
It includes the header file of the base class and shows public inheritance of the base class.
When I run a program, declaring a list of type unorderedLinkedList using this function, this error comes up: 'class unorderedLinkedList<int>' has no member named 'dividedAt'
Well, yeah, it's technically a public member of the base class. Anybody know why it's not being recognized as a member of the class? Thanks.
Any code inside unorderedLinkedList<> that directly references members of the templated base
class must explicitly qualify the members. For example
1 2 3 4 5 6 7 8 9 10 11 12
template< typename T >
class Base {
public:
T foo;
};
template< typename T >
class Derived : public Base< T > {
public:
void print() const
{ std::cout << Base::foo << std::endl; } // Note explicit qualification of foo
};
Thanks for the response, but it's not a function in the derived class that's trying to access a base function. It's an object of the derived class in the driver (main), although more accurately, it's a templated function declared outside main and called within main (since main can't be templated); it can access other members of the base class just fine.