Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macuser571

macrumors newbie
Original poster
Dec 3, 2009
1
0
Hello I am new to this forum so hello everyone!
I have a problem with as it seems to be a compile error when trying to inherit a class from one header file to another. Here is part of the code i think might be the problem:

#ifndef SORTEDLINKEDLIST_H
#define SORTEDLINKEDLIST_H
#include <iostream>
#include "LinkedListType.h"
using namespace std;

template <typename ItemType>
class SortedLinkedList: public LinkedListType<ItemType>
{
public:
// Constructor
SortedLinkedList();
...

I'm pretty sure its this line:

class SortedLinkedList: public LinkedListType<ItemType>

thats causing the problem because i'm getting the error:

/Users/salgarcia/Desktop/hmmm/SortedLinkedList.h:54:0 /Users/salgarcia/Desktop/hmmm/SortedLinkedList.h:54: error: class 'SortedLinkedList<ItemType>' does not have any field named 'LinkedListType'

...when i try to implement these functions:

//**************************************************************
template <typename ItemType>
SortedLinkedList<ItemType>::SortedLinkedList()
:LinkedListType()
{}

//**************************************************************
template <typename ItemType>
SortedLinkedList<ItemType>::SortedLinkedList
(const SortedLinkedList<ItemType>& otherList)
:LinkedListType(otherList)
{}

...please let me know if the inheritance coding is correct or if there is something in Xcode i need to change because it works perfectly in visual studios.

Thank you!
 
1. The gcc compiler often rejects incorrect code that other compilers accepts.
2. From the bits you showed, we can tell - nothing.

3. Please don't use "using namespace" in a header file. Actually, don't use it anywhere.
4. I'm quite sure that LinkedListType is not the base class of SortedLinkedList. The base class is something slightly different.
 
Try changing this:

Code:
template <typename ItemType> 
SortedLinkedList<ItemType>::SortedLinkedList()
:LinkedListType()
{}

...to this:

Code:
template <typename ItemType> 
SortedLinkedList<ItemType>::SortedLinkedList()
:LinkedListType[COLOR="Blue"]<ItemType>[/COLOR]()
{}


Note that I disagree with the general statement that you should never use "using namespace." Yes, you shouldn't do what you did with "using namespace std," but in a very localized scope where you would otherwise be typing the same thing over and over, it's not such a bad thing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.