Help with Inheritence

This is a discussion on Help with Inheritence within the C++ Programming forums, part of the General Programming Boards category; I'm trying to create a program that can perform some functions on both ordered lists and unordered lists, however when ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    5

    Help with Inheritence

    I'm trying to create a program that can perform some functions on both ordered lists and unordered lists, however when I compile I'm getting some errors that I am having trouble figuring out. I have a total of 7 files. A ListType.h and ListType.cpp for my base class, then derived classes of OListType.h and OListType.cpp for ordered lists and UListType.h and UListType.cpp for unordered lists. Then my main program which is named Program04 per directions from my instructor. I'm assuming if I can fix the errors in line 4 of OListType.cpp and UListType.cpp that the errors in the main program will go away. Can anybody point me in the right direction? Thanks for any help you guys can offer

    Here are the errors I'm getting:

    OListType.cpp:4:22: error: ISO C++ forbids declaration of "OlistType" with no type
    OListType.cpp:4:22: error: no "int OListType::OlistType()" member function declared in class "OListType"
    Program04.cpp: In function "int main()":
    Program04.cpp:56:9: error: "IntUList" was not declared in this scope
    Program04.cpp:59:9: error: "IntOList" was not declared in this scope
    UListType.cpp:4:22: error: ISO C++ forbids declaration of "UlistType" with no type
    UListType.cpp:4:22: error: no "int UListType::UlistType()" member function declared in class "UListType"


    Here's the OListType.cpp code that it states the error is in:
    Code:
    #include "OListType.h"
    #include <iostream>
    
    OListType::OlistType(){
    }
    
    OListType::OListType(size_t newsize):ListType(newsize){
    }
    
    OListType::~OListType(){
    }
    
    void OListType::insert(int item){
      if(!this->full()){
        int loc = 0;
        while((loc < this->count) && (this->list[loc] < item))
          ++loc;
        for (int i = this->count; i > loc; --i)
          this->list[i] = this->list[i-1];
        this->list[loc] = item;
        ++this->count;
      }
      else
        std::cerr << "Cannot insert into a full list. \n";
    }
    
    void OListType::erase(int item){
    	if(!this->empty()){
          int loc = 0;
    	  while((loc < this->count) && (this->list[loc] != item))
    	    ++loc;
    	  if(loc < this->count){
    	    for(int i = loc; i< this->count; ++i) {
    	    this->list[i] = this->list[i+1];
            }
          --this->count;
          }
        }
       else
         std::cerr << "The list is already empty. \n";
    }
    And here is the UListType.cpp:
    Code:
    #include "UListType.h"
    #include <iostream>
    
    UListType::UlistType(){
    }
    
    UListType::UListType(size_t newsize):ListType(newsize){
    }
    
    UListType::~UListType(){
    }
    
    void UListType::insert(int item){
      if(!this->full()){
        this->list[this->count]=item;
        this->count++;
      }
      else
        std::cerr << "Cannot insert into a full list.";
    }
    
    void UListType::erase(int item){
      if(!this->empty()){
        int loc=0;
        while ((loc < this->count) && (this->list[loc]!=item))
          ++loc;
        if (loc < this->count){
          this->list[loc] = this->list[count-1];
          --this->count;
        }
      }
       else
         std::cerr << "The list is already empty. \n";
    }

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    458
    Code:
    OListType::OlistType(){
    Constructor has different name from class name, thus the compiler thought you are trying to write a member function so it requires the type.
    Last edited by nimitzhunter; 04-23-2011 at 01:49 AM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    5
    Thank you! Sometimes it just takes a different set of eyes. I must have looked at it for hours.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Abstract inheritence
    By Chris87 in forum C++ Programming
    Replies: 6
    Last Post: 06-18-2009, 11:47 AM
  2. Question about Inheritence
    By chadmandoo in forum C++ Programming
    Replies: 22
    Last Post: 11-30-2008, 12:50 PM
  3. Inheritence and operator[]
    By nempo in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2007, 04:58 PM
  4. Inheritence Question
    By kas2002 in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2006, 09:32 AM
  5. Multiple Inheritence
    By face_master in forum C++ Programming
    Replies: 14
    Last Post: 12-11-2002, 04:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21