Xcode class inheritance error in C++

Discussion in 'Mac Programming' started by macuser571, Dec 3, 2009.

  1. macuser571 macrumors newbie

    Joined:
    Dec 3, 2009
    #1
    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!
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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.
     
  3. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #3
    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.
     

Share This Page