Mac Xcode class inheritance error in C++

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!
 

gnasher729

macrumors P6
Nov 25, 2005
16,684
3,375
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.
 

Detrius

macrumors 68000
Sep 10, 2008
1,621
19
Asheville, NC
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.
 

Similar threads

  • wlisik
11
Replies
11
Views
2K
  • jasnw
2
Replies
2
Views
826
  • gimmesomemo
1
Replies
1
Views
646
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.