错误C2511:在类中没有发现重载成员函数。

时间:2022-01-16 14:10:59

This is the error im recieving.

这是我收到的错误。

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

I believe this is something to do with me trying to use an enum that is included in a header but doesnt seem to be carried over to the other classes.

我相信这与我尝试使用包含在header中的枚举有关,但似乎没有被带到其他类中。

Here are the 2 headers involved and the function im struggling with::

这里有两个标题,以及我正在与之斗争的功能::

Menus.cpp:

Menus.cpp:

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

Menus.h

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

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 header statements

菜单。cpp标题语句

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

#include <string>

using namespace std;

1 个解决方案

#1


4  

  • The enum sortType is defined in Journey.h

    在旅程中定义了enum sortType。

  • however, is not visible in menu.h and you are using enum sortType as input argument in the declaration of member function Menus::sortListBy(sortType,Vector<connections>); in the definition of the Menus class.

    但是,在菜单中看不到。在成员函数菜单的声明中,您使用enum sortType作为输入参数::sortListBy(sortType,Vector );在菜单类的定义中。

  • In Menus.h remove the forward declaration of class Journey; and replace it with #include "Journey.h".

    在菜单。h删除了班级旅行的前向声明;用#include“trip .h”代替它。

  • Remove #include "Menus.h" in Journey.h.

    删除# include”菜单。在Journey.h h”。

  • There should be no problem, since you don't have circular dependency issues between Journey and Menus.

    应该没有问题,因为在旅行和菜单之间没有循环依赖性问题。

#1


4  

  • The enum sortType is defined in Journey.h

    在旅程中定义了enum sortType。

  • however, is not visible in menu.h and you are using enum sortType as input argument in the declaration of member function Menus::sortListBy(sortType,Vector<connections>); in the definition of the Menus class.

    但是,在菜单中看不到。在成员函数菜单的声明中,您使用enum sortType作为输入参数::sortListBy(sortType,Vector );在菜单类的定义中。

  • In Menus.h remove the forward declaration of class Journey; and replace it with #include "Journey.h".

    在菜单。h删除了班级旅行的前向声明;用#include“trip .h”代替它。

  • Remove #include "Menus.h" in Journey.h.

    删除# include”菜单。在Journey.h h”。

  • There should be no problem, since you don't have circular dependency issues between Journey and Menus.

    应该没有问题,因为在旅行和菜单之间没有循环依赖性问题。