未排序列表的错误?

时间:2014-10-08 18:54:46

标签: c++

所以我今晚要完成一份作业,而我正在尝试编译它以进行测试,但是我遇到了一堆错误,其中一些似乎没有任何意义?这些错误提到了以下内容:'语法错误' ::'"等等,但我从来没有遇到过这样的错误,并且对如何解决这些问题一无所知。

UnsortedClass.cpp

#include "UnsortedClass.h"

void UnsortedType::UnsortedType()
{
  length = 0;
}
bool UnsortedType::IsFull() const
{
  return (length == MAX_ITEMS);
}
int UnsortedType::GetLength() const
{
  return length;
}

NBA UnsortedType::GetItem(NBA customPlayer, bool& found) 
{
  bool moreToSearch;
  int location = 0;
  found = false;

  moreToSearch = (location < length);

  while (moreToSearch && !found) 
  {
    switch (customPlayer.ComparedTo(info[location]))
    {
      case LESS    : 
      case GREATER : location++;
                     moreToSearch = (location < length);
                     break;
      case EQUAL   : found = true;
                     item = info[location];
                     break;
    }
  }
  return customPlayer;
}
void UnsortedType::MakeEmpty()
{
  length = 0;
}
void UnsortedType::PutItem(NBA customPlayer)
{
  info[length] = customPlayer;
  length++;
}
void UnsortedType::DeleteItem(NBA customPlayer)
{
  int location = 0;

  while (customPlayer.ComparedTo(info[location]) != EQUAL)
    location++;

  info[location] = info[length - 1];
  length--;
}
void UnsortedType::ResetList()
{
  currentPos = -1;
}
NBA UnsortedType::GetNextItem()
{
  currentPos++;
  return info[currentPos];
}

UnsortedClass.h

#include "NBA.h"
class UnsortedClass  //declares a class data type
{
public: 
    // 8 public member functions
    void UnsortedType ( );
    bool IsFull () const; //checks if list is full
    int GetLength () const ; // returns length of list
    NBA GetItem (NBA customPlayer, bool& found); //gets item specified in parameters
    void PutItem (NBA customPlayer); //puts NBA player in list
    void DeleteItem (NBA customPlayer); //deletes NBA player from list
    void ResetList (); //resets list to 0
    NBA GetNextItem (); //gets next item after current list position
private:
    // 3 private data members
    int length; 
    NBA info[MAX_ITEMS]; 
    int currentPos;
};

NBA.h

#include <string>

using namespace std;
const int MAX_ITEMS = 10;
enum RelationType  {LESS, GREATER, EQUAL};
class NBA {
    private:
        char firstInitial;
        string lastName;
        string team;
        char position;
    public:
        void set_first_initial(char playerFirstInitial);
        void set_last_name(string playerLastName);
        void set_team(string teamName);
        void set_position(char position);
        char get_first_initial();
        string get_last_name();
        string get_team();
        char get_position();
};

我收到的错误如下(图片格式,因为我可以在没有Stackoverflow将其解释为代码的情况下粘贴这些行)

Error List

1 个答案:

答案 0 :(得分:1)

构造函数没有指定返回类型。变化

void UnsortedType::UnsortedType()

UnsortedType::UnsortedType()

它的头部声明中的类名也是错误的;其他地方都说UnsortedType,但这说:

class UnsortedClass  //declares a class data type