错误C2511:在类中找不到重载的成员函数

时间:2014-05-19 12:40:53

标签: c++ visual-studio-2010 enums overloading

这是我收到的错误。

Error   4   error C2511: 'Vector<T> Menus::sortListBy(sortType,Vector<T>)' 
: overloaded member function not found in 'Menus'   z:\documents\visual 
studio 2010\projects\oo_cw\oo_cw\menus.cpp  410 1   OO_CW

我相信这与我尝试使用包含在标题中的枚举有关,但似乎并没有转移到其他类。

以下是涉及的2个标题和我正在与::

进行斗争的函数

Menus.cpp:

 Vector<connections> Menus::sortListBy(sortType sortKey,Vector<connections> sortList){}

Menus.h

#pragma once
#include "std_lib_facilities.h"
#include "Airport.h"
class Journey;
#include <string>



typedef enum {BACK,FORWARD,INVALID,OPTIONS} result;
typedef enum {BOOK,VIEW,EXIT} firstChoice;


class Menus
{
public:
  Menus(void);
  ~Menus(void);
  firstChoice firstMenu();
  Airport bookingMenuFirst(Vector<Airport>);
  Airport bookingMenuSecond(Vector<connections>,Vector<Airport>);
  airlines bookingMenuThird(Airport,Airport,Journey&);
  string bookingMenuDate();
  bool showReciept(string,string,string,string,double,double,double);
  string showRecieptNames();
  void readReciept(string);
  void optionMenu(Journey);
  Vector<connections> sortListBy(sortType,Vector<connections>);
};

Journey.h

#pragma once
#include "std_lib_facilities.h"
#include "Airport.h"
#include <string>
#include "Menus.h"

enum sortType {PRICE,TIME} ;

class Journey
{
 public:
  Journey(void);
  ~Journey(void);
//accessors
  Airport getStart();
  Airport getEnd();
  string getDate();
  airlines getAirline();
  string getStringAirline();
  double getTime();
  double getPrice();
  sortType getSort();
  //modifiers
  void setStart(Airport);
  void setEnd(Airport);
  void setPrice(double);
  void setTime(double);
  void setAirline(airlines);
  void setDate(string);
  void saveBooking();
  void setSort(sortType);


private:
  Airport startAirport;
  Airport endAirport;
  double price;
  double time;
  string date;
  airlines airline;
  Vector<string> splitBy(string,string);
  sortType sortingBy;

};

Menus.cpp标题语句

#include "Menus.h"
#include "std_lib_facilities.h"
#include "Airport.h"
#include "Journey.h"

#include <string>

using namespace std;

1 个答案:

答案 0 :(得分:4)

  • enum sortType

  • 中定义了Journey.h 然而,
  • menu.h中不可见,并且您在enum sortType的定义中使用Menus::sortListBy(sortType,Vector<connections>);作为成员函数Menus声明中的输入参数类。

  • Menus.h中删除class Journey;的转发声明,并将其替换为#include "Journey.h"

  • 删除#include "Menus.h"中的Journey.h

  • 应该没有问题,因为JourneyMenus之间没有循环依赖问题。